7 ms·
iOS 5 doesn't have garbage collection, it has a new compiler-level feature called Automatic Reference Counting which does pretty much what you think it does. It
by schrototo 15y ago
iOS 5 doesn't have garbage collection, it has a new compiler-level feature called Automatic Reference Counting which does pretty much what you think it does. It's basically retain/release without you having to explicitly write retain/release instructions.
(I don't think I'm violating any NDAs here, since ARC was up pretty big on one of the slides at the keynote. In any case, anybody who cares about this stuff is either at WWDC or at least has a dev account and has been pouring over the beta docs since they've gone online.)
- jcnnghm 15y agoI think this is actually a bigger deal from a developers perspective than most of the other announcements. Since it's a compiler feature, does anyone know if it's compatible with older os releases? Once you're familiar with the manual memory management conventions, it's not difficult, but this should make iOS development more approachable.
- schrototo 15y ago"ARC is supported in Xcode 4.2 for Mac OS X v10.6 and v10.7 (64-bit applications) and for iOS 4 and iOS 5. (Weak references are not supported in Mac OS X v10.6 and iOS 4)." But how about looking at the docs yourself?
- jcnnghm 15y agoAren't they behind a password/NDA wall? Perhaps I didn't see that information when I was looking at it?
- schrototo 15y agoI'm sorry, I didn't mean to be snarky. (Although if you're not a member of the dev program, I don't see why you care about this information?)
- prodigal_erik 15y agoAny new platform that isn't ultradoomed is interesting. I might have been waiting for iOS development to become less brittle before getting involved (that is, if their policies towards developers and users weren't so repellent).
- themgt 15y agoIsn't "automatic reference counting" just a specific type of "garbage collection"? But yes, I think this feature really slipped through the cracks in the announcements I've seen so far (even Ars seemed confused about it)
- jcnnghm 15y agoI think this is done at compile time, so it wouldn't be considered garbage collection.
- themgt 15y agoThe compiler is LLVM though, "By enabling ARC with the new Apple LLVM compiler", which begins to blur the difference
- jcnnghm 15y agoI don't think that makes much difference, as long as it's performed at compile time.
- ori_b 15y agoLLVM is being used as a static compiler. There is no LLVM virtual machine - the compiler emits native machine code.
- themgt 15y agoMacRuby does support AOT compilation, although I don't think it's a very production-ready feature yet and would likely be incompatible with a fair percent of existing ruby code
- chc 15y agoThis isn't in MacRuby — it's in Objective-C. And it's explicitly distinct from garbage collection. This is an alternative to garbage collection that has generally been considered kind of impractical. (And MacRuby's AOT compilation works pretty well from what I've seen.)
- aaronharnly 15y agoARC is touted on this public page: https://developer.apple.com/technologies/ios5 https://developer.apple.com/technologies/ios5
- schrototo 15y agoThat's a... peculiar choice of icon. edit: ah, now I get it. Cute.
- zyb09 15y agoI don't get it :( please explain.
- StavrosK 15y agoIt's an arc.
- sanswork 15y agoWhen electricity moves through the air between two points like that its called an arc. (look up electric arc on youtube for examples)
- jannes 15y agoOh, so it isn't a visualization of how ARC works. It's just an image of something else that coincidentally has the same name. I would've never figured that out. Thanks.
- maximilianburke 15y agoI'm not sure why you would say this isn't garbage collection. It performs automatic management and reclamation of resources without programmer intervention. It doesn't operate like the GC's of the JVM or .NET CLI, but then neither to the GCs for other languages like Lua, Python, or Perl.
- dialtone 15y agoPython has a proper GC to remove cycles in reference counting, it's just not the "main" one. http://docs.python.org/library/gc.html http://docs.python.org/library/gc.html Since the collector supplements the reference counting already used in Python, you can disable the collector if you are sure your program does not create reference cycles. Automatic collection can be disabled by calling gc.disable().
- drewcrawford 15y ago> I'm not sure why you would say this isn't garbage collection. Because it isn't. Garbage collection is something that happens at run time by a garbage collector via an algorithm like mark-and-sweep, tri-colour marking, etc, and as a block of code that's called at runtime it A) has a lot of information about your program and B) has a nontrivial performance impact. Unfortunately I can't talk specifics (stupid NDA), but schrototo has said that it's a compiler-level feature, which would automatically disqualify it as being a bona fide garbage collector. Speaking generically, any static feature is going to a great deal less powerful than its dynamic equivalent. Thinking of compile-time memory management as garbage collection is not just a leaky abstraction, it's a broken water main flooding into the street. Think less "auto pilot" and more "cruise control". You still have to understand the accelerator and the break, you just don't have to use them as much.
- maximilianburke 15y agoA garbage collector doesn't need to use an algorithm like mark-and-sweep, or two space copying. It can be something as simple as a system that scans a block of memory looking for any sequence of bytes that appears to be a pointer into managed memory. You don't need special compiler support or extra program knowledge for garbage collection -- conservative collectors can be added to any language, like using the Boehm-Demers-Weiser GC with C or C++. Automatic garbage collection doesn't even require a garbage collector -- the monolithic piece of code that performs the scanning and reclamation of objects -- it simply requires freeing the programmer from the task of managing the storage of an object. Fancy collector algorithms are meant to improve throughput and latency -- you could definitely create an implementation of Java that uses automatic reference counting but you'd be searching for something faster really quickly. If I have a language where I create a number of managed objects and the compiler's escape analysis determines that these objects never leave the function's scope and so changes them to be an alloca then you would have garbage collection without involving a garbage collector. Again, if that's what automatic reference counting is as sold by Apple then I'd consider it to be garbage collection.