Nib ownership and retain count
Nib ownership and retain count
- Subject: Nib ownership and retain count
- From: Ian was here <email@hidden>
- Date: Thu, 24 Jan 2008 09:23:40 -0800 (PST)
I have an interesting issue. I noticed that when I
make an object a Nib file's owner, that my object's
retain count increases by one. So, when I release my
object, it doesn't get deallocated. I found that the
following code works. I was just wondering if there
was a better way.
- (id)init
{
if ( self = [super init] )
{
// Load the Nib file.
NSNib *myNib = [[NSNib alloc]
initWithNibNamed:@"MyNib" bundle:nil];
if ( myNib == nil )
{
NSLog( @"MyNib Nib failed to load!" );
return nil;
}
// Instantiate the Nib file.
if ( ![myNib instantiateNibWithOwner:self
topLevelObjects:&topLevelNibObjects] )
{
NSLog( @"MyNib Nib failed to instantiate!" );
[myNib release];
return nil;
}
[myNib release];
[self release]; // My object's retain count is
now two, drop it down to one.
[topLevelNibObjects copy];
[topLevelNibObjects
makeObjectsPerformSelector:@selector(release)];
}
- (void)dealloc
{
[self retain]; // Must increase my object's
retain count so it doesn't crash.
[topLevelNibObjects release];
[super dealloc];
}
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
_______________________________________________
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