iPhone - how to declare a method and avoid leaks -
suppose have method this
- (uibutton *) createbuttonatx:(cgfloat)vx y:(cgfloat)vy{ //... bla bla bla... //at point have uibutton *mybutton = [[uibutton alloc] initwithframe:myframe]; // have alloc here... // ... more bla bla , return mybutton; }
as button allocated , not released technically leak, right?
on main code, caller like
uibutton *onebutton = [self createbuttonatx:100 y:100]; [myview addsubview:onebutton]; [onebutton release];
in theory, onebutton mybutton on createbutton method being released on main code, so, instruments point method leaking...
how solve that? using autorelease?
thanks
replace last line with
return [mybutton autorelease];
the truth view retains subview when use -addsubview:.
Comments
Post a Comment