【发布时间】:2011-03-15 17:11:49
【问题描述】:
此时我的应用程序有时会崩溃:
NSMutableData* position = [NSMutableData dataWithLength: 3 * sizeof(CGPoint)];
当NSMutableData 调用自动释放时。
这是崩溃日志:
Exception Type: EXC_BREAKPOINT (SIGTRAP) Exception Codes: 0x00000001, 0xe7ffdefe Crashed Thread: 0 Thread 0 name: Dispatch queue: com.apple.main-thread Thread 0 Crashed: 0 CoreFoundation 0x343dea60 _CFAutoreleasePoolAddObject + 136 1 CoreFoundation 0x343de9cc -[NSObject(NSObject) autorelease] + 8 2 Foundation 0x30c49166 +[NSMutableData(NSMutableData) dataWithLength:] + 34
你知道为什么吗?
更新: 变量“position”被返回并以这种方式使用:
NSMutableData *positionData = [[SFinder sharedFinder] move:self.crId] ;
CGPoint *path = [positionData mutableBytes];
CGPoint location0 = path[0];
CGPoint location1 = path[1];
CGPoint location = path[2];
更新 2:
我使用 NSMutableData 删除了代码,但应用总是随机崩溃。在调试控制台上有一条消息:
*** attempt to pop an unknown autorelease pool (0x5830000)
堆栈:
Thread 0 Crashed: Dispatch queue: com.apple.main-thread 0 CoreFoundation 0x01348b69 _CFAutoreleasePoolPop + 201 1 UIKit 0x008a947c _wrapRunLoopWithAutoreleasePoolHandler + 68 2 CoreFoundation 0x013edfbb __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27 3 CoreFoundation 0x013830e7 __CFRunLoopDoObservers + 295 4 CoreFoundation 0x0134bbd7 __CFRunLoopRun + 1575 5 CoreFoundation 0x0134b240 CFRunLoopRunSpecific + 208 6 CoreFoundation 0x0134b161 CFRunLoopRunInMode + 97 7 GraphicsServices 0x029b3268 GSEventRunModal + 217 8 GraphicsServices 0x029b332d GSEventRun + 115 9 UIKit 0x008a942e UIApplicationMain + 1160 10 MyApp 0x000029f4 main + 100 (main.m:13) 11 MyApp 0x00002985 start + 53
【问题讨论】:
-
你的意思是你自己调用自动释放?
-
@HyLian:看起来不像。查看堆栈跟踪。
-
也许你自己在某个地方发布它?或者将其分配给您释放的另一个变量?
-
代码在哪里?你知道当时是否存在自动释放池吗?
-
如果您尝试自己分配/初始化它而不使用 auto 方法会怎样?
标签: iphone objective-c cocoa memory-management