Re: Nib ownership and retain count
Re: Nib ownership and retain count
- Subject: Re: Nib ownership and retain count
- From: Ken Thomases <email@hidden>
- Date: Fri, 25 Jan 2008 10:56:25 -0600
On Jan 24, 2008, at 4:01 PM, Keary Suska wrote:
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.
This is very wrong. Your release method may be called many times
over the object's lifetime, but should only release topLevelObjects
once -- on the last release. Or preferably, on dealloc, if you can
resolve the retain cycle that's preventing the object from being
fully released.
If the nib is primarily for a window, then NSWindowController is a
good way to go. It takes care of loading the nib, managing the top-
level objects, and breaking certain retain cycles which crop up if
the nib objects have bindings to or through the File's Owner.
-Ken
_______________________________________________
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