memory leaks - problem with NSmutableArray -
- (void)createtileonscreen:(cgrect)rect { myarray = [[nsmutablearray alloc] init]; cgrect bounds = rect; cgrect myrect = cgrectmake(bounds.origin.x,bounds.origin.y, (int)(bounds.size.width / 11), (int)(bounds.size.height / 10)); (int = 0; < 10; i++) { (int j = 0; j < 11; j++) { int index = 10 * + j; liv *mytile = [[liv alloc] initwithframe:myrect withindex:index]; float width = (1.0 / 11); float height = (1.0 / 10); [mytile setimagesection:cgrectmake((j / 11), (1.0 - ((i+1) / 10)), width, height)]; [self.rotationview addsubview:mytile]; [myarray addobject:mytile]; [mytile release]; myrect.origin.x += myrect.size.width; } myrect.origin.x = bounds.origin.x; myrect.origin.y = myrect.origin.y + myrect.size.height ; } } #import "liv.h" @implementation liv @synthesize index; - (id)initwithframe:(cgrect)frame withindex:(int)index_ { if (self = [super initwithframe:frame]) { self.index = index_; self.backgroundcolor = [uicolor blackcolor]; fadinganimationduration = 2.0; } return self; } - (id)initwithframe:(cgrect)frame withindex:(int)index_ withcolor:(uicolor *)acolor { if (self = [self initwithframe:frame withindex:index_]) { self.backgroundcolor = acolor; } return self; }
when create tile on screen called few times, see allocations keep increasing. can please let me know how deallocate myarray without leaks , remove super view.
move
myarray = [[nsmutablearray alloc] init];
out of
- (void)createtileonscreen:(cgrect)rect [myarray release];
will release tiles fine. might want iterate through array prior release ,
[[myarray objectatindex:index] removefromsuperview];
Comments
Post a Comment