Reputation: 2513
In my pgm, i am getting a leak warning in this segment.
-(NSMutableArray *)filterArrayForBank:(NSMutableArray *)originalArray withKey:(NSString *)key{ NSMutableArray *mutableArray=[[NSMutableArray alloc]init];
for (int i=0; i<[originalArray count]>0; i++) {
if([[[originalArray objectAtIndex:i]objectForKey:@"transType"] isEqualToString:key]){
[mutableArray addObject:[originalArray objectAtIndex:i]];
}
}
//////NSLog(@"mutableArray %@",mutableArray);
return mutableArray ;
}
if i block this leak by below line, app get crash
either return [mutableArray autorelease];
or
NSMutableArray *mutableArray=[[[NSMutableArray alloc]init]autorelease];
plz help me to stop this leak. thanks in advance.
Upvotes: 0
Views: 139
Reputation: 3383
If you return an autoreleased array you need to make sure you retain it in the caller method. However, if you are not retaining it in the caller method, try renaming the method to:
-(NSMutableArray *)newFilterArrayForBank:(NSMutableArray *)originalArray withKey:(NSString *)key
This will notify the compiler that you are allocating a new NSMutableArray.
Upvotes: 1