When I perform a [NSString release] or [NSArray release] or [NSMutableArray release], what happens?
Does the memory became wiped out?
Or just pushed on the stack and dropped from the heap, or vise versa?
If I just want to dump memory when I am done with it, is “release” the best thing to use?
I am dealing with many matrices and don’t want them sticking around using memory…
thanks
The
retainCountof the instance that you callreleaseon is decremented. If it reaches 0 as a result of your call, then the instance will be deallocated.Not necessarily. The memory may become wiped out (in the sense that it no longer contains a valid object instance and may be overwritten by other things) once the
retainCountreaches 0 (or less if you over-release something), but this is not guaranteed to happen immediately upon your call torelease. The released instance may in fact stick around for quite awhile, if it is associated with anNSAutoreleasePoolthat is not drained frequently or if someone else has calledretainon it.In general, yes. If you want really low-level control of things, you can also use
malloc()andfree()instead, which will release memory more immediately than callingreleasewill.