0
votes

Can anyone tell me why this is method is giving me leaks? I've been looking at it for ages and can't figure out why its leaking. The leaked object is ContactOperations. the EventType is Malloc and Release. I thought the init might be wrong?

Contact Controller

ContactOperations *contactOps = [[ContactOperations alloc] initWithDatabase:database];
if ([contactOps applicationIsOwner])
    [contactOps startOperations];    
[contactOps release];

Instruments says the alloc is giving me the leak...

Contact Operations

ContactOperations
- (id)initWithDatabase:(Database*)aDatabase
{
    if (self = [super init])
    {
        database = [aDatabase retain];
        parameter = [[Parameter alloc] init];
        parameter.database = aDatabase;
        //addressBook = ABAddressBookCreate();
    }
    return(self);
}



-(void)dealloc
{
    [database release];   
    [parameter release];
    //CFRelease(addressBook);
}
1
Have you tried static analysis from inside Xcode?trojanfoe
Is contactOps retained somewhere in -[ContactOperations startOperations]? Other than that, there are no leaks in the code you posted.Costique
Stupid question: does it still give the warning if you set contactOps to nil after the release? If not, you technically have an overreleased instance still reachable from your code.Monolo
@trojanfoe - static analysis doesn't find anything.Jon Wells
@Costique its not retained this is the only way its used.Jon Wells

1 Answers

5
votes
-(void)dealloc
{
    [database release];   
    [parameter release];
    //CFRelease(addressBook);
}

You have forgotten [super dealloc]; at the end of - (void) dealloc. You have to call [super dealloc] in order to clear instance variables of ContactOperations' superclass.