2011-08-15 153 views
-1

我知道还有很多问题需要解决,我试着去关注他们,但我仍然无法弄清楚问题所在。iOS内存管理问题

我已经启用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,然后在dealloc方法的每个方法的末尾尝试[object release],我已经发布了该类的所有属性。

任何人都可以给我一个暗示,我需要做什么?如有必要,我可以包含更多代码。

+0

后。的。码。 – akashivskyy

回答

0

你的应用程序中有一个字符串,你已经发布了。由于autoreleasepool发布时出现问题,您意外地释放了一个自动释放对象。这里是什么可能会导致这样一个例子:

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 

没有任何相关的代码,我所能做的是提供作为模式,为您寻找在你的代码的问题。

+0

谢谢。我会看看我能否找到这种模式。我有没有办法让调试器显示哪个字符串导致崩溃? –

+0

嗯,如果我的方法中使用这个早些时候: '的NSString * thisChar = [[NSString的页头] initWithFormat:@ “”];' 我可以再使用 'thisChar = [NSString的stringWithFormat: @“%C”,tempChar];' 在使用此末端之前 '[thisChar release];' 或者这可能是问题所在? –

+0

这将是你的问题!你需要移动'[thisCar release];'重新分配它或完全移除release,只使用'stringWithFormat:',所以你不要调用alloc,因此不需要释放。 – Joe