All the tutorials I have done say that I set stuff to nil in viewDidUnload and then release in dealloc. However I am being told that this would cause a memory leak since viewDidUnload gets called before a dealloc and so I am unable to release anything that is set to nil.
Can someone help clarify?
If you create an object (with
allocandinit) inviewDidLoad, then you shouldreleaseit inviewDidUnload. The reason is that sometimesviewDidUnloadis called to save memory, butdeallocis not called. Then, later,viewDidLoadmay be called again. In general, release anything you allocate in the inverse method, e.g.If you allocate an object in
init, then release it indealloc.If you allocate an object in
viewDidLoad, then release it inviewDidUnload.If you allocate an object in
viewWillAppear(orviewDidAppear), then release it inviewWillDisappear(orviewDidDisppear).