objective-c - 从 NSString 调试 EXC_BAD_ACCESS

标签 objective-c xcode debugging iphone-sdk-3.0 exc-bad-access

我的控制台中有一条 EXC_BAD_ACCESS 消息。我在 this site 上阅读了有关环境变量 NSZombieEnabled 和 MallocStackLoggingNoCompact 的信息.我创建了我的环境变量:NSZombieEnabled = YESMallocStackLoggingNoCompact = 1。在控制台中,我看到了

2010-03-01 19:13:46.924 CruzNomad[7952:207] *** -[CFString stringByAddingPercentEscapesUsingEncoding:]: message sent to deallocated instance 0x58448e0

然后在 (gdb) 提示符下,我执行了 info malloc-history 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 行使用相同的方法发送到 Google 进行反向地理编码。

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

即使在这里,它也表示“超出范围”。我很难过……有什么建议吗??

谢谢!

托马斯

最佳答案

在大多数情况下,当您不保留对象属性并在其他方法中向其发送延迟消息时,就会发生这种情况。

所以,在初始化一些字符串的地方尝试:

[fullAddress retain];

[myString retain];

取决于哪个在其他方法中初始化。

关于objective-c - 从 NSString 调试 EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2360273/

相关文章:

iphone - 如何在 iOS 中更改 ePub 图书的字体颜色和字体样式?

ios - 识别 UIScrollView 中的滑动手势

iphone - 舍入到 "beautiful"值

iphone - 2 Xib 的 1 个 IBOutlet 对象具有相同的文件所有者?

python - 你如何从 Objective-C 调用 PyObjC 代码?

iPhone didSelectRowAtIndexPath 没有触发

swift - xcode 8 自动布局 uiimageview 问题

asp.net - 如何阻止 MonoDevelop 在调试时打开 Safari 窗口?

python - 从 BBEdit/TextWrangler 在 Shell (IDLE) 中运行 Python 脚本

c++ - 从结构中打印单词