Re: Nib ownership and retain count
Re: Nib ownership and retain count
- Subject: Re: Nib ownership and retain count
- From: Keary Suska <email@hidden>
- Date: Thu, 24 Jan 2008 15:01:33 -0700
- Thread-topic: Nib ownership and retain count
on 1/24/08 1:48 PM, email@hidden purportedly said:
> Yes, you are correct about dealloc not getting called without the [self
> release] in the init method. According to the documentation, NSNib has several
> benefits over NSBundle (which is what I was using before), mainly, its better
> optimized when instantiating multiple copies of the same Nib file.
Yeah--I probably got it backwards. Anyway, your existing code wouldn't
benefit from the load-once, instantiate-many functionality offered by NSNib.
Sans this functionality, the NSBundle interface seems much more intuitive to
me, and it is much more obvious what is happening memory-wise (IMHO). But to
ac their own.
> I overrode my object's release method and released the top level objects when
> my retain count hit one, hoping that whatever Nib object was retaining my
> object would release it, but that didn't work.
A simple search of the archives, and reviewing some very recent threads,
never, ever, ever rely on retain count for *anything*. Ultimately, it's none
of your code's business. That being said, your release method would simply:
1) [topLevelObjects release] and 2) [super release] . That should be enough
to release everything as soon as the current autorelease pool is drained,
and as long as you aren't needlessly retaining.
> From what I gathered from the documentation, the returned array of top level
> objects are autoreleased, meaning that they would need to be retained by the
> array containing them.
This isn't entirely correct as stated: the returned topLevelObjects array is
autoreleased; each top level object has a retain count of 1 upon
instantiation, *plus* when they are added to the array, the array retains
the object, so they have a retain count of 2. That's why you call -release
on them--so that only the array owns the objects. Thus releasing the array
should release the objects. Note that these retain counts are not
necessarily true counts, but just what you need to be concerned about. One
top level object may be retaining another for some reason, for which you
shouldn't need to be concerned (unless it is your object and you aren't
releasing properly, or have created a retain cycle).
Best,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden