I having a warning when i analyze my code for memory leak from xcode. I tried for hour to figure it out but couldn’t understand, but i have some suspicion on specific code:
[stack push:[outputString copy]];
[stack print]; //here xcode tell there is potential leak of an object that is createn on above line
and my stack implementation is:
-(void) push:(NSString *)element{
[store addObject:element];
top++;
}
-(void) print{
NSLog(@"%@", [store objectAtIndex:top]);
}
- (void)dealloc {
[store release];
[super dealloc];
}
and this is my init for my stack class:
-(id) initWithMutableArray{
self = [super init];
if(self){
store = [[NSMutableArray alloc] init];
top = -1;
}
return self;
}
My suspicion is on code [outputString copy]. But i am storing it on array and i am releasing store array on dealloc.
Gracias.
There is no
releaseto balance the[outputString copy]so it is leaked. When adding the object to your array it gets retained by the array and released when the array is destroyed.