objective c - Where's the memory leak? -
i'm adding custom view tableheaderview following code:
imagebutton = [uibutton buttonwithtype:uibuttontyperoundedrect]; imagebutton.frame = cgrectmake(120, 12, 64, 64); imagebutton.titlelabel.font = [uifont systemfontofsize:10]; imagebutton.titlelabel.linebreakmode = uilinebreakmodewordwrap; imagebutton.titlelabel.textalignment = uitextalignmentcenter; [imagebutton settitle:nslocalizedstring(@"choose\nphoto", @"choose\nphoto") forstate:uicontrolstatenormal]; [imagebutton addtarget:self action:@selector(photobuttonpressed) forcontrolevents:uicontroleventtouchupinside]; // add existing image, if any, button if (child.thumbnailimage != nil) { [imagebutton setbackgroundimage:child.thumbnailimage forstate:uicontrolstatenormal]; } // add button view self.headerview = [[uiview alloc] initwithframe:cgrectmake(22, 12, 70, 70)]; [headerview addsubview:imagebutton]; // add view table header self.tableview.tableheaderview = headerview;
the memory leak showing on alloc line above headerview uiview. i'm declaring uiview , uibutton in header file , releasing in viewdidunload , dealloc, i'm not sure i'm doing wrong. also, showing on device , not simulator (just thought i'd mention).
any appreciated.
thanks,
rod
you're using headerview setter method (self.headerview
) need release uiview instance assign headerview property, either using release
or autorelease
.
e.g.
uiview* newheaderview = [[uiview alloc] initwithframe...]; self.headerview = newheaderview; [newheaderview release];
or
self.headerview = [[[uiview alloc] initwithframe:...] autorelease];
the reason because headerview
setter method automatically retains object assigned it.
alternatively, can set headerview instance variable directly, without using property setter method:
[headerview release]; // release existing object headerview = [[uiview alloc] initwithframe:...];
Comments
Post a Comment