FROM : Ian was here
DATE : Thu Jan 24 18:23:40 2008
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
DATE : Thu Jan 24 18:23:40 2008
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
| Related mails | Author | Date |
|---|---|---|
| Ian was here | Jan 24, 18:23 | |
| Hamish Allan | Jan 24, 19:37 | |
| Keary Suska | Jan 24, 19:39 | |
| Ian was here | Jan 24, 21:48 | |
| Hamish Allan | Jan 24, 22:30 | |
| Keary Suska | Jan 24, 23:01 | |
| Ken Thomases | Jan 25, 17:56 | |
| Keary Suska | Jan 27, 17:53 |






Cocoa mail archive

