views:

41

answers:

1

My iPhone app generally uses under 5MB of living memory and even in the most extreme conditions stays under 8MB. The iPhone 2G has 128MB of RAM and from what I've read an app should only expect to have 20-30MB to use.

Given that I never expect to get anywhere near the memory limit, do I need to care about memory warnings and setting objects to nil in viewDidUnload:? The only way I see my app getting memory warnings is if something else on the phone is screwing with the memory, in which case the entire phone would be acting silly. I built my app without ever using viewDidUnload:, so there's more than a hundred classes that I'd need to inspect and add code to if I did need to implement it.

+2  A: 

Yes, please free all memory that you don't use!

Behaviours like this are one of the reasons Apple doesn't allow multiple Apps to run at the same time. Now imagine sometimes they will and all programs would be written like this...

FRotthowe
So I went ahead and implemented viewDidLoad: and used accessors to set visual elements and outlets to nil (hundreds of classes, only some dozen viewControllers :p).I see what you're saying, though at this point it seems to be something necessary more in theory than in current reality. I chose to do it anyway to save any future problems if Apple does choose to allow multi-tasking with iPad or iPhone 4G.
iPhoneToucher
As a side note, a question I'm asking myself now is: For the viewControllers where I use custom init methods and set various visual elements in those init methods (and do nothing in viewDidLoad), how do I handle this? According to the documentation you should only release objects that will be reloaded when the view loads, but this doesn't generate another customInit call...Guess I have some reorganizing to do?
iPhoneToucher
First, as KennyTM writes, setting members to nil doesn't do anything but leak memory. You need to -release the objects!Second, of course for members you release in viewDidUnload you need to do the initialization in viewDidLoad. Maybe you should take a deeper look into http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html and learn what is really happening when you alloc, release (or autorelease) objects.
FRotthowe