What should i release in viewdidunload




















My problem is like this: Parent class loads a child view. Child removes itself during an action by using "removeFromSuperView".

Parent class gets a When I Apple's code blows up before then. I've been reading all day about why views should be set to nil in viewDidUnload and released in dealloc. All the articles keep on repeating the same thing. Yes I know, when the view How can I do it manually?

What is the - void viewDidUnload is good for? Could I not just relase everything in -dealloc? If the view did unload, wouldn't -dealloc be called anyway? This happens often inside a -viewDidLoad method, like this:. On iPhone OS 2. You could release the whole view controller's view if that made sense. Or just big memory-consuming contents in it. Now, in the new OS 3. The reason: If a view controller holds references to childs of the view, i.

After they are released in -viewDidUnload, they can get freed up from memory. Apple deprecated viewWillUnload, now you shoud use didReceiveMemoryWarning or dealloc to release your objetcs.

If you were using these methods to release data, use the didReceiveMemoryWarning method instead. You would need to test that the view is not in a window before doing this. If the view controller is popped from the navigation controller stack and is not retained anywhere else, it will be deallocated, and dealloc will be called instead of viewDidUnload.

You should release the views created in loadView in dealloc, but it is not necessary to set the variables to nil, because soon after dealloc is called the variables will no longer exist. You should use retained outlets instead. And you should really think about climbing that fence and joining us on the Automatic Reference Counting side. Unbelievably, the grass is just as green here as it looks. Previous Post. Next Post. Skip to content A lot of people misunderstand the point of viewDidUnload.

Make your outlets unload automatically The idea behind viewDidUnload is that the view is being unloaded out from behind your view controller.

This is not stated in the online materials. Personal humble opinion, please correct me if something is wrong! PS: Many friends say that viewDidUnload cannot be debugged, but it is actually possible. You can try to check the effect of NSLog in the opened viewController. NSLog can be used directly in dealloc. Question 1: Who should release. What should be released in viewDidUnload is:. Anything that will be recreated in viewDidLoad.

This statement is not necessarily true.



0コメント

  • 1000 / 1000