Reputation: 53
I have just started a new Xcode project for the first time since downloading the latest version of Xcode. Right away I noticed that when declaring a property in the .h file, it is not automatically synthesized in the .m file, nor is it set to nil in the ViewDidUnload stub. Furthermore...there is no ViewDidUnload IBAction stub. After a little research here on stack overflow, I realize this is new and normal.
I also noticed the new didReceiveMemoryWarning and that someone wrote the following about it: use didReceiveMemoryWarning if you want to free memory not related to views or the other UI objects.
My question is this...Before, Xcode would automatically set properties to nil in viewDidUnload. It does not set them to nil in didReceiveMemoryWarning. Should I manually set these to nil in the didReceiveMemoryWarning stub or just leave the stub empty as it is when Xcode creates the .m file? Is there anywhere where properties need to be set to nil when no longer used or does Xcode automatically do that now?
Thanks!
Upvotes: 1
Views: 102
Reputation: 299545
The memory used by most UI elements is really trivial. That is one of the reasons that iOS has deprecated (and now no longer calls) viewDidUnload
. It just doesn't matter enough to justify the trouble (including possible bugs).
didReceiveMemoryWarning
is where you should reduce any significant memory usage. In particular, it's a good place to dump any cached information that you can reconstruct. You should be looking at things in the range of at least 10s of kB in my opinion. Dumping a few hundred bytes generally isn't worth the code required to manage it (code that itself require memory, plus testing and maintenance). You may not require didReceiveMemoryWarning
at all in many programs if you don't cache a lot. (And there are other tools, like NSCache
, which are better than hand-coding didReceiveMemoryWarning
anyway.)
Upvotes: 1