Reputation:
For some reason my app was crashing on a particular action. After investigation, I found out it is because of releasing something that has already been released. Then I read on the internet that I can track down the cause of this using NSZombie and MallocStackLogging which I implemented and got this as the result.
NSZombie: 2011-01-19 14:39:09.523 iota[13649:207] * -[CFString release]: message sent to deallocated instance 0xeeaf510
malloc_history
ALLOC 0xeeaf510-0xeeaf52f [size=32]: thread_a0041500 |start | main | UIApplicationMain | GSEventRun | GSEventRunModal | CFRunLoopRunInMode | CFRunLoopRunSpecific | CFRunLoopRun | __CFRunLoopDoTimer | __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION | __NSFireDelayedPerform | -[UITableView _userSelectRowAtIndexPath:] | -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] | -[CorpDirViewController tableView:didSelectRowAtIndexPath:] | -[CorpDirPersonViewController corpDirViewController:shouldContinueAfterSelectingContact:] | -[ContactItem mergeWithContact:] | -[ContactItem getValueForProperty:] | ABRecordCopyValue | CPRecordCopyProperty | CPRecordGetProperty | ABCMultiValueLoad | ABCDBContextFetchMultiValuePropertyIntoRecord | ABCDBContextFetchMultiValueEntries | CPSqliteStatementSendResults | CollectMultiValueEntries | _sqliteStatementApplyValuesFromRecordWithNullValue | CFStringCreateWithCString | __CFStringCreateImmutableFunnel3 | _CFRuntimeCreateInstance | malloc_zone_malloc
Now I am unable to find out particularly what is causing the crash. Can anyone help me out with it?
Upvotes: 0
Views: 1013
Reputation: 92336
As you already know, you are calling release
on an object that is already destroyed. That is, you've called release
one time too many on the object (in this case an NSString). The exception done via NSZombieEnabled now tells you where the "one time too many" release is done. But most of the time you are searching for the release in between, and that is harder to do...
Now that you know where it is crashing (and should thus know which variable is involved) you need to read through your code where you're also releasing this variable or how objects get assigned to that variable and then inspect those sources. That is, you need to "backtrack" where the object originated from and what you've done with it. Somewhere along its life you either forgot to retain
it, or you accidentially release
/autorelease
d it where you shouldn't.
Upvotes: 1
Reputation: 12036
Verify your alloc/ release on that string. Numbers of alloc+retain must be equal to numbers of release. Do not release an autorelease object.
Upvotes: 0