Question

If I am receiving memory warnings where exactly I have to release all my views & data ?

Whether I have to release in

- (void)didReceiveMemoryWarning or in

- (void)viewDidUnload

Was it helpful?

Solution

For iPhone OS 3.0 and later viewDidUnload maybe called during low memory situtations so best to release views in viewDidUnload, just note that for custom views, create them at viewDidLoad instead of init method of the class.

didReceiveMemoryWarning is used more for releasing custom data structures instead of releasing views.

OTHER TIPS

- (void)didReceiveMemoryWarning

This is supposed to be used only on things that you dont and wont need anymore so put here what is strictly innecessary, for instance if you are not using a view anymore and maybe it wasnt released you can release it here so when the memory warning comes it will be released.

- (void)viewDidUnload

Here you make sure that the views will be released in case they are referenced additionally by a view controller. You can refer to this question: When to use viewDidUnload

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top