iphone - Memory management : release viewcontroller object after adding to NSMutableArray -



iphone - Memory management : release viewcontroller object after adding to NSMutableArray -

i have memory leak below code. if utilize [sub release];after adding sub nsmutablearray(subviewcontroller), analyzer says "inconrrect decrement of reference count of object not owned @ point caller", when remove [sub release] says "potential leak of 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 utilize autorelease warning becomes "object sent -autorelease many times"

subcategoryviewcontroller *sub =[[[subcategoryviewcontroller alloc] initwithserviceurl:urlstring andheadervalue: ((pmcategory *)[self.data objectatindex:i]).categoryname]autorelease];

added comment: subcategoryviewcontroller init method:

@property (nonatomic, retain) nsmutablearray *data; @property (nonatomic, copy) nsstring *headertext; @synthesize info = _data; @synthesize headertext=_headertext;

...

self = [super init]; if (self) { self.data = [[nsmutablearray alloc] init] ; self.headertext =headervalue; self.serviceurl =serviceu; self.firstload = yes; } homecoming self;

it because haven't followed proper naming convention of objective c. whenever writing initialization function namingconvention like

-(id) initfirstwordsecondword{ }

means create first letter after init capital.

so alter initwithserviceurl initwithserviceurl , problem solved. cheer up!!!

iphone memory-management analyzer

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -