I have a custom UIView which gets loaded through a NIB inside a UIViewController.
I’ve been struggling with a -[UIScrollView retainCount]: message sent to deallocated instance error all day.
My custom UIView subclass dealloc method looked like this:
-(void)dealloc {
[myScrollView dealloc];
[someProperty dealloc];
[super dealloc];
}
The problem was that it was always crashing on [super dealloc] because of the [myScrollView dealloc] preceding it.
When I changed the method around to:
-(void)dealloc {
[super dealloc];
[myScrollView dealloc];
[someProperty dealloc];
}
Everything is working fine. My question is, does it make a difference if [super dealloc] is called first or last? In most examples I see it called last.
[super dealloc]should always be the last call indealloc. Your problem is that you should be callingreleaseon the other objects, notdealloc.deallocis called by the runtime when the release count of the object reaches zero, your code should never call it directly.Your code should therefore actually look like: