How do I decide when I should release memory? Because If I release the memory, many times the application crashes.
+1
A:
Try the apple documentation on memory management in objective-c.
http://developer.apple.com/mac/library/documentation/cocoa/conceptual/MemoryMgmt/MemoryMgmt.html
Paul Hankin
2010-08-19 07:06:25
+3
A:
You should release memory when you've finished with it. Objects are reference counted so, as long as you retain
and release
(and everyone else does too), you should have no problems.
If you find you're crashing because you release the memory, then either you or someone else isn't following the rules.
In either case, find out who isn't following the rules, and fix it. Don't hold on to memory just to avoid crashes. That way lies madness (and lack of memory).
paxdiablo
2010-08-19 07:06:56
I think it helps to think of it as releasing objects rather than memory. The actual memory gets deallocated by the runtime which sends a dealloc message to the object when the retain count becomes zero.
Plumenator
2010-08-19 07:12:10
+1 for madness. Learn to grok lifetime of your allocations or go insane. There's not much middle ground available....
RBerteig
2010-08-19 07:14:42