Next Post: DidUnload vs. dealloc question

The clarification question is as follows:

What exactly should I do in viewDidUnload? When should I free objects - (void) viewDidUnload and not in -dealloc

So, let's say there is a small memory error, and the view is hidden, and viewDidUnload is called. We do a release and dance zero. Later, the entire view stack is not needed, so dealloc is called. Since I already have a release and zero in viewDidUnload, I don't have it in dealloc. Perfect.

But if there is no low memory error, viewDidUnload is never called. dealloc is called, and since I have no release and zero stuff, there is a memory leak.

In other words, will a call to dealloc ever be called without calling viewDidUnload?

and the practical follow up is that if I Alloc and set something in viewDidLoad, and I let it go and set it to zero in viewDidUnload, I leave it from dealloc, or I do a defensive check zero in dealloc and release / zero if it not zero?

+7
memory-management objective-c iphone
source share
1 answer

Release him in both. You do not need to check for zero. Release to zero does nothing.

However, viewDidUnload does not release ivars, which you cannot easily recreate in viewDidLoad if the view loads again.

Usually (without memory warnings) viewDidUnload is not called, only dealloc is called.

+8
source share

All Articles