ios - Correctly releasing returned UIImage -
i call following method image display in uiimageview. when done uiimageview release myimageview.image. happy how instruments showing leak of uiimage. how should releasing below instance of uiimage?
-(uiimage *)getimagewithref:(nsstring *)ref { uiimage *myimage = [[uiimage alloc] initwithcontentsoffile:[nsstring stringwithformat:@"foobar_%@",ref]]; if (myimage == nil) { myimage = [[uiimage alloc] initwithcontentsoffile:@"foobar_defaultimage"]; } return myimage; } thanks in advance
try using auto-release when return image.
-(uiimage *)getimagewithref:(nsstring *)ref { uiimage *myimage = [[uiimage alloc] initwithcontentsoffile:[nsstring stringwithformat:@"foobar_%@",ref]]; if (myimage == nil) { myimage = [[uiimage alloc] initwithcontentsoffile:@"foobar_defaultimage"]; } return [myimage autorelease]; }
Comments
Post a Comment