I've got a crash that happens at a critical point in our application. However, the crash appears to be coming from an overreleased UIView object (more specifically the header view of a UITableView, which in this case is a UISearch bar). The odd thing about this is that that was instantiated from a nib file. Here's the crash...
I've setup my nib file to match exactly what Apple has in one of its sample projects.
I've also taken the time to analyze this with NSZombieEnabled and using Instruments. However I still can't make heads or tails as to why this is happening. Here's the Pairing of Retain/Releases....
And the stack trace exposing when the UIView object is created.
The common example of this type of error is an NSError object that is created and assigned to an out parameter within an autorelease block. However, I would not expect to see the same problem with a UIView. Nor do I see an autorelease block anywhere in my code (save the one on the main run loop). Any thoughts on how I might solve this problem?
The Problem is, that listening for notifications or adding an KVO observer does not change the retaincount of the observing object. And there seems to be a notification fired right after the deallocation of you're view/viewcontroller/object.
You could changed the - (void)dealloc
Method to remove the notification/KVO observer from your view/viewcontroller
Notifications:
-(void) dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
//if you are not using ARC you also have to write
//[super dealloc];
}
For KVO use Method with your keypath(s)
- (void)removeObserver:(NSObject *)anObserver forKeyPath:(NSString *)keyPath
Cheers, Nils
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With