Reputation: 1571
If you set a property to nil in viewDidUnload do you need to release it again in dealloc?
Upvotes: 3
Views: 361
Reputation: 17906
No, but:
[nil release]
is fine.viewDidUnload
being called.So just release as normal in -dealloc
.
Of course, you must make sure that you actually released the previous object. You implicitly do this if you used the synthesized setter:
self.myProperty = nil; // good
// or
[self setMyProperty:nil]; // also good
But setting the ivar to nil will leak:
self->myProperty = nil; // leaky as a sieve
// or
myProperty = nil; // as useful as a screen door on a submarine
These are common errors.
Also note that setting properties to nil in -dealloc
is a bad idea. As Kendall points out in the comments, you may unexpectedly invoke KVO behavior. There's a fuller discussion at Properties in dealloc: release then set to nil? or simply release.
Upvotes: 4