Re:Is C++ the Language of the Future?
by mrich on Friday March 23, 2012 @12:11PM
(#3745782)
Objective-C with ARC comes pretty close.
[ Parent
| on HN ]
Out of curiosity, when does the GC happen there? Does Objective-C have strict enforcement of destruction-on-scope exiting?
(not a Objective-C dev, so don't know)
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.
I'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!