HamasN
HamasN

Reputation: 534

Incorrect decrement of the reference count of an object that is not owned at this point by the caller in iPad

-(id)init
{
if (self = [super init]) 
{
    self.dmrPlaylists = [[[NSMutableArray alloc] initWithCapacity:0] autorelease];
     }
}
-(void)dealloc
{   
[self.dmrPlaylists release];
}
-(DMRPlaylist *)getDMRPlaylistByUUID:(NSString *)deviceUUID
{
if (deviceUUID == nil)
    return nil;

for(int i = 0; i < self.dmrPlaylists.count; i++)
{
    DMRPlaylist * dmrPlaylist = [self.dmrPlaylists objectAtIndex:i];
    if([dmrPlaylist.deviceUUID isEqualToString:deviceUUID])
    {
        return dmrPlaylist;
    }
}

return nil;
}

Memory(Core Foundation/Object-C) Incorrect decrement of the reference count of an object that is not owned at this point by the caller.

Thanks in advance.

Upvotes: 1

Views: 463

Answers (2)

jemmons
jemmons

Reputation: 18657

You haven't told us what part of the above code causes the error. Step through it with the debugger to isolate where it happens and get back to us.

Also, you haven't given us enough code to know what's wrong. For example:

self.dmrPlaylists = [[[NSMutableArray alloc] initWithCapacity:0] autorelease];

probably ultimately calls -setDmrPlaylists: with an autoreleased mutable array. Where is -setDmrPlaylists: defined? Is it declared by a @property statement and @synthesizeed? If so, is it declared as a retain property? If not, then the setter will never call retain on the mutable array. And when the autorelease decrements the mutable array's retain count at the end of the event loop, it will likely be deallocated leaving you pointing at junk memory.

Upvotes: 0

borrrden
borrrden

Reputation: 33423

1) Do not use self.dmrPlaylists in your init and dealloc methods. Instead, interact with the underlying variable.

2) Call [super dealloc]

Without knowing which line the warning is on, can't be sure, but these are problems.

Upvotes: 1

Related Questions