discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about object initialization and autorelease


From: Omar Campos
Subject: Re: Question about object initialization and autorelease
Date: Sat, 31 Mar 2012 17:37:29 -0430

Hi David,

  Thanks for your reply.
 
ARC is Automatic Reference Counting.  It means that the compiler inserts the retain / release / autorelease messages for you automatically, and the optimiser elides them when it can prove that they are redundant.


Oh, right. I've heard about this, but only as "reference counting", not the term ARC. Personally, I wouldn't mind using it, if it saves me the trouble of having to release objects by myself.

Objective-C pointer variables hold either owning or non-owning references.  An owning reference is one that contributes to the retain count, a non-owning reference does not.


Thanks for clarifying that.

 
> Sorry if I am sound like a total newbie ('cause I actually am!). As I said, my Obj-C experience is with the iOS frameworks, particularly Cocoa Touch. And, in my year and two months experience, I haven't had the need to use -autorelease (or maybe there was, and my apps are leaking memory!).

If you have never used autorelease, your code is almost certainly either trivial or wrong.  That said, if you have used synthesised properties, then you have probably used autorelease without even being aware of it.


Well, what I usually do is declare my properties with @synthesize, initialize them by either calling [[alloc] init] or connecting them to visual objects in XCode's Interface Builder. The book I read on this also taught me to call -release for every property on the class's -dealloc method. Is this wrong?

I think I'm also gonna take the time to read up on Obj-C memory management, to better get a grasp on it :)

Sincerely,
Omar

reply via email to

[Prev in Thread] Current Thread [Next in Thread]