Could a double release cause a crash?
My iOS app has been crashing with some users. I was able to retrive their crash logs and symbolicate them.
Almost every crash looks like this...
0 libobjc.A.dylib 0x34a80466 objc_msgSend + 18
1 CoreFoundation 0x357e0f74 -[NSObject(NSObject) release] + 24
2 CoreFoundation 0x357e53c2 CFRelease + 62
3 CoreFoundation 0x35825fe6 -[__NSArrayM removeObjectAtIndex:] + 82
4 CoreFoundation 0x358237ae -[NSMutableArray removeAllObjects] + 30
5 [appName] 0x00006396 -[MainView actionSheet:clickedButtonAtIndex:] (MainView.m:790)
As you can see on 2 and 1, my array was released twice. Right after the second release the app sends objc_msgSend and the app crashes. Is it crashing because the array is being release twi开发者_StackOverflow中文版ce?
Also, my array is created like this:
someArray = [[NSMutableArray alloc] init];
I only release this array in my dealloc like this:
- (void)dealloc {
[someArray release];
}
As the result that I only release it once, in my dealloc, how could it crash because of being released twice?
Lastly, another weird thing about this crash is it only happens sometimes, it's not consistent. As you can see on line 5 of the crash log, a actionsheet button is pressed. There is only one line being executed on that press:
[someArray removeAllObjects];
This crash has got me completely puzzled, and I would appreciate it if someone could help me understand exactly why it's crashing and how I could prevent it crashing in the future.
Thanks in advance!
It certainly looks like a double-release, but it's probably one of the objects in the array, not the array itself. To track it down, run your app under the Zombies Instrument from Xcode. It's best to do this in the Simulator, because this takes a load of memory. Now when you reproduce the crash, you'll find out what class the offending object was. You'll also be able to track its retain/release history to find out where you're breaking it.
This doesn't look like a release message sent to your array - this looks like a release message sent to one of the objects you're storing inside of the array.
If I understood this correctly, you're removing an object from your array, it then gets released, and then the system tries to send that object a message.
精彩评论