Re: Should objects returned by indirection be autoreleased
Re: Should objects returned by indirection be autoreleased
- Subject: Re: Should objects returned by indirection be autoreleased
- From: Lon Giese <email@hidden>
- Date: Fri, 12 May 2006 20:23:08 -0700
No don't assume that... the doc for setRepresentedObject: does not say
that NSCell will retain it... so it wont... if you dont explicitly
release the it you will have a memory leak... things like targets,
delegates and such are not retained by the object you pass it to...
The hard and fast rule is if you create it ( any init method or any
copy method ) or retain it then you have to release it... If you
didn't create it or retain it then you MUST NOT release it. NSArray
for example will retain objects added to it, but the rule still
holds... If you create an object (retain count 1) then add it to a
NSArray now the object has a retain count of 2, when you release the
array, NSArray will release the object, now it has a retain count of
1... it is still occupying memory... So weather or not NSCell
retains the represented object or not, you must still release it
yourself if you created it (with init...) or copied it.... However
NSCell does not retain the object so if you release the object while
NSCell still has it's id you'll likely get a stern warning or crash
when NSCell tries to send a message to it... clear as mud? you'll
figure it it after you track down several crashes in the autorelease
pool... when the autorelease pool crashes you know an object was
released too many times...
On May 12, 2006, at 6:42 PM, Eric wrote:
Thanks for all your response. Here's another memory related problem
I've
just hit upon:
NSCell has the property "representedObject". If I subclass NSCell and
set
and use the property from within my subclass (by calling
setRepresentedObject:), then can I assume it will be automatically
deallocated in [super dealloc]? In other words, I can just use this
property without doing anything.
Thanks again,
Eric
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden