3 ms·
Yes, Objective-C will reclaim your retained objects promptly (unless you use the deprecated Objective-C garbage collection, which few do and never worked on iOS
by ootachi 15y ago
Yes, Objective-C will reclaim your retained objects promptly (unless you use the deprecated Objective-C garbage collection, which few do and never worked on iOS).
The exception is the autorelease pool, which gets dumped at the end of every turn of the event loop. You can promote or demote objects from the autorelease pool at will.
Anyway, the biggest problems with Obj-C memory management are (a) you can't allocate objects on the stack, so you're forced into using the autorelease pool for stuff, and (b) you can promote or demote objects from the autorelease pool at will, which means that even the autorelease pool has to malloc, thus you don't get the nice benefits of super-cheap bump allocation that C++ arenas (or a generational GC's nursery) buy you.
- angersock 15y agoI'm still a little puzzled by the phrase "promptly"--you mean as soon as it goes out of scope, right? Like, immediately? Anyways, thank you for the information!
- ootachi 15y agoRight, as soon as it goes out of scope. (Or when you call release to drop the last reference on it, if you aren't using ARC.)