If I compile and run the following code, the ivars in the parent and  
child classes are released.

For some reason I was thinking that the subclass' dealloc wouldn't be  
called.  Since it is called, we don't have to do anything if super  
returns nil...right?  I'm fully confused now.

#import <Foundation/Foundation.h>
@interface Parent : NSObject
{
     NSString *_parentName;
}
@end

@interface Child : Parent
{
     NSString *_string;
}
@end

@implementation Parent

- (id)init
{
     _parentName = [@"parentName" copy];
     self = [super init];
     if (self) {
         [self release];
         self = nil;
     }
     return self;
}

- (void)dealloc
{
     NSLog(@"dealloc parent %@, release _parentName %@", self,  
_parentName);
     [_parentName release];
     [super dealloc];
}

@end

@implementation Child

- (id)init
{
     _string = [@"test" copy];
     unsigned ptr = (unsigned)self;
     self = [super init];
     if (nil == self) {
         NSLog(@"super init failed for 0x%x", ptr);
     }
     return self;
}

- (void)dealloc
{
     NSLog(@"dealloc child %@, releasing _string %@", self, _string);
     [_string release];
     [super dealloc];
}

@end

int main (int argc, char const *argv[])
{
     NSAutoreleasePool *pool = [NSAutoreleasePool new];

     Child *c = [Child new];

     [pool release];
     return 0;
}


-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Bibdesk-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-develop

Reply via email to