Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Trent Burkenpas
Trent Burkenpas
22,388 Points

Use Automatic Reference Counting ?

I'm working on the Blog Reader app, and im on the video "starting Over." Amit tells you to check "Use Automatic Reference Counting" But Mine does not have that option, Is that going to be a problem? I think its because I have a older version of xcode.

Here is the link to the video: http://teamtreehouse.com/library/build-a-blog-reader-iphone-app-2/rebuilding-from-scratch/starting-over-2

Amit talks about it at the :55 second mark

Thanks!

4 Answers

Patrick Cooney
Patrick Cooney
12,216 Points

Yeah. Very big problem. Without ARC you need to manually manage memory. It's a guess but I'd think if you tried to do the tutorial without ARC you'd run out of memory pretty quickly.

Edit: To be more clear, ARC, as the name implies, automatically keeps track of references to your objects. When you have 0 references to your object the runtime knows it's safe to clear the memory. I never did it the old way but from what I was told by my instructor you had to set a variable to manually keep track of your reference count and when it got to 0 you could manually send a release message.

Your instructor may not be too familiar with Objective-C... That said, reference counting is still a paradigm applicable to all other OO languages and when implemented for e.g. Java, you would do just that. Objective-C just had a more structured way than others.

The old way in Objective-C involves invoking the methods retain, release, and autorelease directly to the object when appropriate. There were books dedicating lengthy discussions on explaining when you should retain/release. In Obj-C, the retain count and related methods in Objective-C are also defined for you in NSObject, from which all objects descend. So these methods and the internal counter are available to all objects, i.e. you don't have to keep a separate variable to keep track of the retain count. Also, when a retain count gets to zero, the object's dealloc method is called automatically, i.e. you don't have to manually send a free/dealloc message.

These are all extra credit now that ARC has made things so easy. But when you have a memory leak, understand reference counting is still crucial in fixing it.

(If you can profile your app with Instrument, you can actually monitor these counts even with ARC on.)

Ops... bad example... Java has GC, maybe C++ would be the other language that could use manual reference counting.

Don't worry about it. You must have Xcode 5 or above. Amit was using Xcode 4.5.

ARC is now enabled by default, that's why they are no longer showing the option to enable it. To turn it off, you have to go into project and change an option under Build Settings.

Trent Burkenpas
Trent Burkenpas
22,388 Points

ok, wow thanks for all the info

Trent Burkenpas
Trent Burkenpas
22,388 Points

Im having another issue, because of the different versions of xcode. At the end of that same video Amit sets MainStoryboard.storyboard as the Main storyboard in the project settings. I do not have that option all i see is Main Interface. I have the same xcode version as Amit had in making a simple app. But Why does he use a older version of xcode for the blog reader app. I'm assuming they filmed the blog reader app before the simple app. Thanks