I've been dusting off the old programming skills lately, or what's left of it, and have been trying to get into the Mac / iOS programming game, and while I know the basics of programming (I've done a little bit of BASIC, C, Java, etc), I'm going head first into "Learn Objective-C on the Mac" by Mark Dalrymple and Scott Knaster. Most of the topics have been straight forward, and I've got my head around OOP thanks to Java, but there are a few sections that I've read over 4-5 times, and my head still hurts. Those being: * Memory management * Properties * Categories * Protocols With the introduction of iOS 5, I've read in a few places that garbage collection will be coming to into play. Does that mean that I can not worry so much about retaining and releasing objects? Is it like Java where I could just abandon an object and it'd be automatically released? (If it's not as simple as I'm hoping it'd be, to what extent do I need to focus on this?) I guess my other question is, in terms of beginning iOS programming, how important is it that I master properties, categories, and protocols? Obviously I could write an app where you push a button and it says "hey you pushed the button", but how far could I get into writing apps before I'm stuck because I haven't mastered those topics? I'm thinking maybe I can slowly start on books about iOS programming, but if the consensus is that these topics are absolutely necessary, I'd rather drill it into my head until I finally got it before moving on. Any advice/opinions/motivational speeches would be gladly appreciated.
iOS 5 is under NDA and all registered developers are prevented from discussing it. All I can tell you is there if you search for "Automatic Reference Counting" on this site you'll get some information.
Ah, that's good new then So to the OP: this is not garbage collection. But it will have a similar effect on your code. If you enable this you no longer need to release/retain/autorelease. But unlike GC there is no runtime performance hit as all the analysis is done up front by the compiler.
And for all the people saying this is necessary, and is awesome in Java. Tests have proven it's not the best to use, because if you have a memleak, it won't show you, eventually your app will crash.. like the java apps using like 300 mb of your ram, when it should be using like 5.. So in my honest opinion, keep to manually doing everything It's hard, but it's worth it
Doing it manually won't show you when you have a leak either. ARC isn't the same as garbage collection. It just automates what you already do with retain/release *you can think of it as the compiler putting the retain/release calls in for you. That's good in some ways, as you don't get the slowdown of a runtime garbage collector, but it does mean you have to follow a few conventions (such as tagging which are weak and strong references, and not casting objects to pointers directly) in order to make it work. Regarding whether to use automatic memory management or not, I'd say that programmer error causes way more leaks and bugs than an inefficient memory management system (be it garbage collection, ARC or whatever).
I have quite high hopes for this. As it's all done in the compiler/static analyser it should be able to warn about memory leaks/persistent objects before the code is even executed.
For memory management, read: http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.pdf Think of properties as a shortcut to writing "setter" and "getter" methods. Code: @synthesize value; is a shortcut to implementing "setValue" and "value" methods. The memory management details of the methods created (nonatomic, retain, assign, etc) are covered somewhat in the Memory Management pdf. It is a must read.
Having worked with Cocoa for quite some time, I must admit that it will be difficult to work with ARC. I think I will stick to the old principles, as they give you a better understanding of the Objective C memory management internals, and they give you a better understanding of programming in general. I just hope that Apple will continue to allow non-ARC projects in Xcode 4. I don't want to adopt this feature, at least not yet.
Seems like ARC would work better as an auto complete thing... just like the brackets and stuff. You insert a retain in your init function, it automatically sticks a release in your dealloc. It makes it easier for you while letting you know what exactly is happening with memory in your program.
All this would do is increase the amount of stuff you have to type and you still wouldn't know exactly what is happening with the memory in your program (i.e. where things are being released). In reality, if you read up on how ARC works, you should have a very good idea of what is happening with your memory.