2010-03-02 97 views
5

我的控制台中有一条EXC_BAD_ACCESS消息。我读了关于this site的环境变量NSZombieEnabled和MallocStackLoggingNoCompact。我创建了我的环境变量:NSZombieEnabled =是MallocStackLoggingNoCompact = 1。在控制台中,我看到从NSString调试EXC_BAD_ACCESS

2010-03-01 19:13:46.924 CruzNomad [7952:207] *** - [CFString字符串 stringByAddingPercentEscapesUsingEncoding:]: 消息发送到释放实例 0x58448e0

然后在(GDB)的提示,我做信息的malloc历史0x58448e0,这给了我:

Alloc: Block address: 0x058448e0 length: 64 
Stack - pthread: 0xa0b33500 number of frames: 25 
    0: 0x98e089bc in malloc_zone_malloc 
    1: 0x21516aa in _CFRuntimeCreateInstance 
    2: 0x2152bf8 in __CFStringCreateImmutableFunnel3 
    3: 0x21567d9 in CFStringCreateCopy 
    4: 0x21742fc in _CFStringCreateWithFormatAndArgumentsAux 
    5: 0xdb546 in -[NSPlaceholderString initWithFormat:locale:arguments:] 
    6: 0xdb4d8 in +[NSString stringWithFormat:] 
    7: 0x23aa3 in -[BuisnessCardViewController viewDidLoad] at /Users/.../Classes/BuisnessCardViewController.m:85 
    8: 0x3d6796 in -[UIViewController view] 
    9: 0x347b4 in -[gm_menuViewController btn5_Pressed:] at /Users/.../Classes/menuViewController.m:535 
    10: 0x357459 in -[UIApplication sendAction:to:from:forEvent:] 
    11: 0x3baba2 in -[UIControl sendAction:to:forEvent:] 
    12: 0x3bcdc3 in -[UIControl(Internal) _sendActionsForEvents:withEvent:] 
    13: 0x3bbb0f in -[UIControl touchesEnded:withEvent:] 
    14: 0x370e33 in -[UIWindow _sendTouchesForEvent:] 
    15: 0x35a81c in -[UIApplication sendEvent:] 
    16: 0x3610b5 in _UIApplicationHandleEvent 
    17: 0x2984ed1 in PurpleEventCallback 
    18: 0x2197b80 in CFRunLoopRunSpecific 
    19: 0x2196c48 in CFRunLoopRunInMode 
    20: 0x298378d in GSEventRunModal 
    21: 0x2983852 in GSEventRun 
    22: 0x362003 in UIApplicationMain 
    23: 0x2c8c in main at /Users/.../source/main.m:14 
    24: 0x2bfa in start 

第7行表示问题出现在BuisnessCardViewController.m的第85行。这条线是在这里:

fullAddress = [NSString stringWithFormat:@"%@ %@", fullAddress, myString]; 

我追加fullAddressmyString的的内容,并将其存储在回fullAddress

如果我正确解释此问题,看起来在此行之后,fullAddress被解除分配。当我放下断点并将鼠标悬停在变量上时,其值将显示为“超出范围”。

fullAddress在本方法后面工作。我用它发送给谷歌,用于采用相同方法的第164行反向地理编码。

NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", [fullAddress stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 

即使在这里,它表示“超出范围”。我难住...任何建议?

谢谢!

托马斯

+0

你可以发布更多的上下文吗?如果它说变量超出范围,我们能否看到整个范围? – 2010-03-02 01:16:22

+0

您是否在其他地方使用'fullAddress'或'myString'? – FelixLam 2010-03-02 01:19:53

+0

另外,万一发生意外,您的商业公司拼错了。 – dreamlax 2010-03-02 03:18:47

回答

3

在大多数情况下,这种情况发生时,你不保留它是对象的属性,并在后期发送消息给它其他方法,迟到。

因此,在某些字符串初始化尝试:

[fullAddress retain]; 

[myString retain]; 

取决于哪一方的其他方法进行初始化。

+0

如果回答不完全清楚,请原谅我的语言,并写下下面的评论。 – mxg 2010-03-02 02:03:33

1

你试过追加字符串格式?

fullAddress = [NSString stringWithFormat:@"%@ %@", fullAddress, myString]; 

有:

- (NSString *)stringByAppendingFormat:(NSString *)format ... 

这样的:

[fullAddress stringByAppendingFormat:@" %@", myString]; 
+0

感谢您的回复,伙计们。不,我不知道生意拼错了。 @dreamlax - 我没有写那个类(谢天谢地): - )...我只是在处理特定的功能。感谢您指出它! 我想出了我的问题。由于stringWithFormat返回一个自动释放对象,我刚刚在方法的第一次使用它之后保留了它。 [fullAddress retain]; 做了窍门(正如我现在看到mxg建议)。 再次感谢大家! -Thomas – Thomas 2010-03-02 04:44:47

相关问题