• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Nib ownership and retain count
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Nib ownership and retain count
      • From: Keary Suska <email@hidden>
    • Re: Nib ownership and retain count
      • From: "Hamish Allan" <email@hidden>
  • Prev by Date: Re: compress / decompress zip file in WinZip 11 format
  • Next by Date: RE: compress / decompress zip file in WinZip 11 format
  • Previous by thread: RE: compress / decompress zip file in WinZip 11 format
  • Next by thread: Re: Nib ownership and retain count
  • Index(es):
    • Date
    • Thread