Re: retain, release, autorelease (was Checkboxes and NSBox titles)
Re: retain, release, autorelease (was Checkboxes and NSBox titles)
- Subject: Re: retain, release, autorelease (was Checkboxes and NSBox titles)
- From: jgo <email@hidden>
- Date: Wed, 20 Jun 2001 12:39:29 -0700
>
John Hvrnkvist wrote:
>
Autorelease is excellent for handling leaking references, as in
>
- (id)aValue
>
{
>
return [[value copy] autorelease];
>
}
>
or
>
+ (id)something
>
{
>
return [[[Something alloc] init] autorelease];
>
}
>
>
Its use in forms like
>
Something* object=[[[Something alloc] init] autorelease];
>
[object doSomething];
>
is simply wasteful. This form is clearer and has less overhead:
>
Something* object=[[Something alloc] init];
>
[object doSomething];
>
[object release];
>
>
In some cases you have no reason to care about overhead, but in general
>
I'd not include get/set methods in that.
Could someone provide a snippet that shows or words that explain
how it works with containers/collections. It always bothered me
in C++ because it seemed like I was either eating at least twice
as much memory as was strictly required (get the info, use it to
initialize objects, add the objects to the collection...) or
futzing over exactly what got destructed when (what constituted
scope), and I'd rather avoid that in Objective-C/Cocoa.
I've looked at the articles provided by Scott A on his stepwise site:
Don Yachtman "Hold Me, Use Me, Free Me"
Manu Iyengar "Memory Management with Cocoa/WebObjects"
and the latter has somewhat of an example with an array, but though
the comments say that collections retain their objects, I don't see
the many temporary objects being released... perhaps because the
example uses an auto-release pool? But if that is so, I don't see
what determines which pool objects get allocated in.
John G. Otto Nisus Software, Engineering
www.infoclick.com www.mathhelp.com www.nisus.com software4usa.com
EasyAlarms PowerSleuth NisusEMail NisusWriter MailKeeper QUED/M
Will program Macs for food.