On Apple's public iOS 5 page they state: Automatic Reference Counting Automatic Reference Counting (ARC) for Objective-C makes memory management the job of the compiler. By enabling ARC with the new Apple LLVM compiler, you will never need to type retain or release again, dramatically simplifying the development process, while reducing crashes and memory leaks. The compiler has a complete understanding of your objects, and releases each object the instant it is no longer used, so apps run as fast as ever, with predictable, smooth performance It's a compiler feature; not an OS feature so I don't see why it wouldn't work with older versions.
On Apple's public iOS 5 page, they state: Automatic Reference Counting Automatic Reference Counting (ARC) for Objective-C makes memory management the job of the compiler. By enabling ARC with the new Apple LLVM compiler, you will never need to type retain or release again, dramatically simplifying the development process, while reducing crashes and memory leaks. The compiler has a complete understanding of your objects, and releases each object the instant it is no longer used, so apps run as fast as ever, with predictable, smooth performance.It's a compiler feature; not an OS feature so I don't see why it wouldn't work with older versions.
3 That's not garbage collection. – Josh Caswell Jul 4 at 23:02 2 No, it's better than garbage collection. The compiler knows what needs to be released and when, so all memory management is taken care as if you did it yourself.
Much more efficient than GC as it doesn't use resources while the app is running. – Brandon Schlenker Jul 4 at 23:19 1 Expanding on Josh's point, this won't help if you have objects of a cyclical nature - ie, for the simplest case, 2 objects that refer to eachother with nothing else refering to them. Their reference counts will never decrease to zero and so they will not be removed.
Edit: @Brandon: in part why we use GC :p – Callum Rogers Jul 4 at 23:19 1 @Brandon, The compiler knows what needs to be released and when, so all memory management is taken care as if you did it yourself. You mean it deals w/ cyclic references too? Either way, ref.
Counting is slower than a good garbage collector and it's very slow for multi-threaded code. – bestsss Jul 4 at 0:27 1 @Yar: ARC is still reference counting — it's just automatic. Reference-counting algorithms aren't able to detect retain cycles.
Cycle detection requires something more sophisticated and would incur more overhead at runtime. – Chuck Jul 4 at 22:15.
You appear to be talking about Automatic Reference Counting, mentioned in other answers. ARC is a kind of GC in that it automates memory freeing, but has a number of differences from a good garbage collector. Firstly, it's mainly a compiler technology.
The compiler knows about Cocoa's reference-counting guidelines, so it inserts retains and releases where they should be according to the rules. It works just like if you'd written the retains and releases yourself — it simply inserts them for you. Normal garbage collectors keep track of your program's memory while it is running.
Second, since it is just like retain and release, it can't catch retain cycles (if Object A retains Object B and Object B retains Object A, and nothing else references either of them, they both become immortal). You need to take the same precautions to prevent them. It also uses resources differently from an automatic garbage collector.
Garbage collectors have to scan for unreferenced memory and collect it — which is expensive, and can lead to "stuttering" on slower systems — but they only have to do this occasionally, and can even fine-tune their collection cycles to match how a program actually uses its memory. In general, a GC program will use more memory than a non-GC program and will slow down significantly when the GC decides to collect. ARC, on the other hand, moves the "scanning" to compile-time and frees memory as soon as it's available, but it has to constantly update object reference counts instead of waiting for garbage to build up like a collector.
Great stuff, thanks, @Chuck. "You need to take the same precautions to prevent them" as what? Meaning you need to avoid using "retain" properties on delegates, etc.? Also: will one declare properties as retain or assign at all?
What about rewriting setters for a retain property, does the dev use retain then? – Yar Jul 17 at 20:37 @Yar: Yes, avoiding retains on delegates is a big one. Rather than assign, though, you'll want to use weak for unretained properties.
As for using retain in a setter: ARC mode makes it illegal to explicitly send retain, release or autorelease. You just assign and the compiler will insert retains and releases where it thinks they're necessary. – Chuck Jul 17 at 22:09 Thanks @Chuck, helps a lot.
So is this available with XCode or it's tied to the iOS 5 SDK? In other words, can you compile like this for iOS 4. X?
I imagine not. – Yar Jul 18 at 1:21 1 @Yar: The specifics of what versions it will be enabled for are under NDA and quite possibly subject to change, but it is a combination of a compiler feature and a runtime library that implements some of the functionality (particularly weak references). Currently there are two ways to use ARC: 1) Get Xcode 4.2 from the iOS developer program; or 2) Download a recent release of LLVM yourself and use that as your compiler.
– Chuck Jul 18 at 2:07 Thanks @Chuck, helpful as usual. I would LOVE to rip up my current project and ARC it, but I promise to start with a World first :) – Yar Jul 18 at 2:25.
Automatic Reference Counting implements automatic memory management for Objective-C objects and blocks, freeing the programmer from the need explicitly insert retains and releases. You will worry less about memory management. There is public info available on the subject: ARC replacing GC?(lists.apple.Com) Automatic Reference Counting (clang.llvm.
Org). This is the tech spec on ARC. If the spec is too harsh to read, in short, you will need to edit the retain/release code to use ARC, but old programs remain compatible.
What you shouldn't do is mix both.
Normal garbage collectors keep track of your program's memory while it is running. Second, since it is just like retain and release, it can't catch retain cycles (if Object A retains Object B and Object B retains Object A, and nothing else references either of them, they both become immortal). You need to take the same precautions to prevent them.
It also uses resources differently from an automatic garbage collector. Garbage collectors have to scan for unreferenced memory and collect it — which is expensive, and can lead to "stuttering" on slower systems — but they only have to do this occasionally, and can even fine-tune their collection cycles to match how a program actually uses its memory. In general, a GC program will use more memory than a non-GC program and will slow down significantly when the GC decides to collect.
ARC, on the other hand, moves the "scanning" to compile-time and frees memory as soon as it's available, but it has to constantly update object reference counts instead of waiting for garbage to build up like a collector.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.