3 ms·
The biggest change so far seems to be a new memory management style called AAM, "Always Autorelease Mode". It's described on the compiler's Github page: https:
by pavlov 10y ago
The biggest change so far seems to be a new memory management style called AAM, "Always Autorelease Mode". It's described on the compiler's Github page:
https://github.com/Codeon-GmbH/mulle-clang https://github.com/Codeon-GmbH/mulle-clang
"The transformed methods will return objects that are autoreleased. Hence the name of the mode. The net effect is, that you have a mode that is ARC-like, yet understandable and much simpler."
This is like a halfway house between traditional Objective-C's "semi-manual" memory management, and the modern ARC (Automatic Reference Counting). Autorelease pools were a cornerstone of the traditional model: autoreleased objects will typically stick around until the end of the event loop cycle, which was a reasonable way to do garbage collection in mostly UI-centric Obj-C apps.
ARC replaced this model with static reference tracking in the compiler: instances are freed when the compiler knows that the last reference has gone out of scope. This is obviously more memory-efficient than the autorelease pool, and that was probably a big factor in Apple's decision to go with ARC (as the primary focus of Obj-C had shifted to iOS).
In summary, the Mulle compiler tries to combine the programmer ease-of-use of ARC with the simpler compiler/runtime implementation of traditional Obj-C memory management. The tradeoff is memory usage and incompatibility with some modern code that assumes an ARC compiler.
Here's a list of language features that the compiler will support:
https://www.mulle-kybernetik.com/weblog/2015/mulle_objc_present_and_absent.html https://www.mulle-kybernetik.com/weblog/2015/mulle_objc_pres...
Personally I agree with the author's positions in principle, but not entirely in practice. In particular, not supporting the property dot syntax will make it unnecessarily difficult to compile most Obj-C code written since about 2009. Same goes for blocks -- they're very integrated in Obj-C APIs by now, even though it does add substantial runtime complication.
- mpweiher 10y ago> autoreleased objects will typically stick > around until the end of the event loop cycle They stick around until their reference count drops to zero. The -autorelease is turned into a -release when the containing autorelease pool is released, so you have full control over when that happens. @autoreleasepool { [[[NSObject alloc] init] autorelease]; } The object is freed at the end of that block. Yes, there is a default autorelease pool for the event loop.
- pavlov 10y agoI know. That's why I wrote "typically".
- pjmlp 10y ago> This is obviously more memory-efficient than the autorelease pool, and that was probably a big factor in Apple's decision to go with ARC Another big factor was the failure of implementing a tracing GC. It had even more corner cases than ARC, it was quite easy to make it crash given the underlying C semantics and developers mixing frameworks, not all of them GC enabled. The good idea behind ARC is that just automates what framework developers were already manually doing with Cocoa.
- dilap 10y agobesides being substantially integrated, blocks are just hella-handy. objc programming got way more pleasant when blocks were added.