【问题标题】:iPhone Memory Error - when using Build & Debug, How to debug?iPhone 内存错误 - 使用 Build & Debug 时,如何调试?
【发布时间】:2011-01-09 18:29:17
【问题描述】:

我是新手,需要一些关于在模拟器上运行的 iPhone 应用程序的帮助。该应用程序在 Build & Run 或 Build & Run - breakpoints off 的情况下运行良好,但在 Build & Debug - Breakpoints on 的情况下运行时会崩溃。任何帮助或想法将不胜感激。朗

细节:没有设置断点,永远不会得到任何可见的模拟器结果,在初始化阶段似乎会在它可以生成任何输出之前爆炸。应用程序的来源是Dan & Tracey Pilone 的“Head First iPhone development”一书中的 DrinkMixer 示例(示例建立到第 280 页)。

出现此错误消息:

Attaching to process 970.
Pending breakpoint 1 - "*0x01c1b001" resolved
Program received signal:  “EXC_BAD_ACCESS”.
No memory available to program now: unsafe to call malloc
Data Formatters temporarily unavailable, will re-try after a 'continue'. (Not safe to call dlopen at this time.)
No memory available to program now: unsafe to call malloc
---
Leaks:
The only object noted as "leaked Object" is:
Leaked Object   #   Address Size    Responsible Library Responsible Frame
Malloc 128 Bytes <blank> 0x3c11950   128Bytes   CoreGraphics    open_handle_to_dylib_path
___

Object Allocations shows (Highest at top = CFString):

Category   --- Overall Bytes  --  #Overall    -- Live Bytes --  #Living
* All Allocations * 497kb      #5888    496kb   #5878   10
CFString                42kb     #1126   42kb       
Malloc  32.00 KB    32kb     #1     32kb
Malloc 1.00 KB  29kb     #29        29kb
Malloc 8.00 KB  24kb     #3     24kb    
Malloc 32 Bytes 20.81kb  #666   20.75kb
Malloc 1.50 KB  19.5kb    #13       19.5kb 
CFDictionary (key-store)    17.64kb  #159  17.64kb 

(note:  Except for "All Allocations, the  #Living is the same as #Overall)
---

List of Calls from Debugger:

#0  0x01c1b010 in CFStringCreateByCombiningStrings
#1  0x023a0779 in LoadFontPathCache
#2  0x023a096b in Initialize
#3  0x023a0f3e in GSFontCreateWithName
#4  0x003d4575 in +[UIFont boldSystemFontOfSize:]
#5  0x002cddaa in +[UINavigationButton defaultFont]
#6  0x002d9e37 in -[UINavigationButton initWithValue:width:style:barStyle:possibleTitles:tintColor:]
#7  0x002cdc75 in -[UINavigationButton initWithImage:width:style:]
#8  0x00468eeb in -[UIBarButtonItem(Static) createViewForNavigationItem:]
#9  0x002d1b56 in -[UINavigationItem customRightView]
#10 0x002d20e3 in -[UINavigationItem updateNavigationBarButtonsAnimated:]
#11 0x002d1e1a in -[UINavigationItem setRightBarButtonItem:]
#12 0x00002e7b in -[RootViewController viewDidLoad] at RootViewController.m:41
#13 0x00313796 in -[UIViewController view]
#14 0x00311d92 in -[UIViewController contentScrollView]
#15 0x0031c2b4 in -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:]
#16 0x0031b32e in -[UINavigationController _layoutViewController:]
#17 0x0031cd1a in -[UINavigationController _startTransition:fromViewController:toViewController:]
#18 0x0031831a in -[UINavigationController _startDeferredTransitionIfNeeded]
#19 0x004362e4 in -[UILayoutContainerView layoutSubviews]
#20 0x035342b0 in -[CALayer layoutSublayers]
#21 0x0353406f in CALayerLayoutIfNeeded
#22 0x035338c6 in CA::Context::commit_transaction
#23 0x0353353a in CA::Transaction::commit
#24 0x00295ef9 in -[UIApplication _reportAppLaunchFinished]
#25 0x0029bb88 in -[UIApplication handleEvent:withNewEvent:]
#26 0x002976d3 in -[UIApplication sendEvent:]
#27 0x0029e0b5 in _UIApplicationHandleEvent
#28 0x023a3ed1 in PurpleEventCallback
#29 0x01bb6b80 in CFRunLoopRunSpecific
#30 0x01bb5c48 in CFRunLoopRunInMode
#31 0x00295e69 in -[UIApplication _run]
#32 0x0029f003 in UIApplicationMain
#33 0x00002ba0 in main at main.m:14

代码,包括第 41 行(如下所示)如下。并感谢格式化帮助和评论:

#import "RootViewController.h"  
#import "DrinkDetailViewController.h";
#import "DrinkConstants.h"
#import "AddDrinkViewController.h"
@implementation RootViewController
@synthesize drinks, addButtonItem;
- (void)viewDidLoad {
    [super viewDidLoad];    
    //  add PATH for PLIST  
    NSString *path = [[NSBundle mainBundle] pathForResource:
                      @"DrinkDirections"  ofType:@"plist"]; 
    NSMutableArray *tmpArray = [[NSMutableArray alloc]                              initWithContentsOfFile:path];   
    self.drinks = tmpArray; 
    [tmpArray release];

// Next is Line #41 - I removed earlier empty lines & Comments

    self.navigationItem.rightBarButtonItem = self.addButtonItem;

}
- (IBAction) addButtonPressed: (id) sender {
    NSLog(@"Add button pressed!");

【问题讨论】:

  • 那么你在 RootViewController.m 的第 41 行周围做什么?显示一些代码。

标签: iphone debugging memory simulator


【解决方案1】:

您是否尝试过使用 Instruments 和 NSZombie 检测: http://www.markj.net/iphone-memory-debug-nszombie/

【讨论】:

    猜你喜欢
    • 2011-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-20
    • 2019-11-14
    • 2016-10-17
    • 2019-01-17
    • 2014-04-13
    相关资源
    最近更新 更多