I have a custom UIView which gets loaded through a NIB inside a UIViewController.
I've been struggling with a -[UIScrollView retainCount]开发者_StackOverflow中文版: 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 in dealloc
. Your problem is that you should be calling release
on the other objects, not dealloc
. dealloc
is 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:
-(void)dealloc {
[myScrollView release];
[someProperty release];
[super dealloc];
}
精彩评论