I have a memory leak with below code. If I use [sub release];after adding sub to NSmutableArray(subViewController), Analyzer says “Inconrrect decrement of the reference count of an object that is not owned at this point by the caller”, when i remove [sub release] then it says “Potential leak of an object allocated on xx line”
for (int i=0; i<[self.data count]; i++) {
SubCategoryViewController *sub =[[SubCategoryViewController alloc]
initwithServiceUrl:urlString andHeaderValue:
((PMCategory *)[self.data objectAtIndex:i]).categoryName];
[[AppDelegate sharedAppDelegate].viewController.subViewControllers addObject:sub];
[sub release];
}
Alson if I use autorelease Warning becomes “Object sent -autorelease too many times”
SubCategoryViewController *sub =[[[SubCategoryViewController alloc]
initwithServiceUrl:urlString andHeaderValue:
((PMCategory *)[self.data objectAtIndex:i]).categoryName]autorelease];
Added from comment:
SubCategoryViewController Init method:
@property (nonatomic, retain) NSMutableArray *data;
@property (nonatomic, copy) NSString *headerText;
@synthesize data = _data;
@synthesize headerText=_headerText;
…
self = [super init];
if (self) {
self.data = [[NSMutableArray alloc] init] ;
self.headerText =headerValue;
self.serviceURL =serviceU;
self.firstLoad = YES;
}
return self;
it is because you haven’t followed proper naming convention of Objective c. Whenever you are writing any initialization function namingConvention is something like
means make first letter after init Capital.
So change your
initwithServiceUrltoinitWithServiceUrland your problem will be solved.cheer up!!!