iOS内存管理问题

时间:2011-08-15 22:27:22

标签: ios memory-management nszombieenabled

我知道有很多问题要处理,我已经尝试过了,但我仍然无法解决问题所在。

我启用了NSZombiesEnabled,收到错误消息:

2011-08-15 23:13:12.368 appName[3926:207] *** -[CFString release]: message sent to deallocated instance 0x4cf4570

如果我在错误后输入 bt ,我会得到此堆栈跟踪:

#0  0x00f92657 in ___forwarding___ ()
#1  0x00f92522 in __forwarding_prep_0___ ()
#2  0x00f3804c in CFRelease ()
#3  0x00f5d18d in _CFAutoreleasePoolPop ()
#4  0x007a53eb in -[NSAutoreleasePool release] ()
#5  0x0004e3ee in _UIApplicationHandleEvent ()
#6  0x0125a992 in PurpleEventCallback ()
#7  0x01002944 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()
#8  0x00f62cf7 in __CFRunLoopDoSource1 ()
#9  0x00f5ff83 in __CFRunLoopRun ()
#10 0x00f5f840 in CFRunLoopRunSpecific ()
#11 0x00f5f761 in CFRunLoopRunInMode ()
#12 0x012591c4 in GSEventRunModal ()
#13 0x01259289 in GSEventRun ()
#14 0x00051c93 in UIApplicationMain ()
#15 0x00002739 in main (argc=1, argv=0xbfffefd8) at main.m:14

我假设这条线正在解释问题,但我真的不确定:

#7  0x01002944 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()

我想我可能会迷失何时应该释放物品。我尝试在每个使用 alloc 的方法结束时执行[object release],然后在 dealloc 方法中我发布了该类的所有属性

我需要做什么?

1 个答案:

答案 0 :(得分:0)

您的应用程序中有一个字符串已过度发布。由于释放自动释放池时出现问题,因此意外释放了自动释放的对象。以下是可能导致此问题的示例:

NSString *autoString = [NSString stringWithFormat:@"A formatted string! %d", 0];

//use string

[autoString release];//This will cause a crash about the same place your crash is

如果没有任何相关代码,我可以做的就是为您提供代码中的问题。