Objective C memory leak problem -


i have memory leak problem in following objective c code. boldasterisked(***) line line memory leak (mentioned in instrument). idea of it? thanks.

- (uiimage*)part:(float)part ofimage:(uiimage*)imgobject withmask:(uiimage*)imgmask {  uiimage *imgresult = nil;  cgrect rcmask = cgrectmake(0.0f, 0.0f, imgmask.size.width, imgmask.size.height);  cgrect rcobject = cgrectmake(0.5f * (rcmask.size.width - imgobject.size.width), 0.0f, imgobject.size.width, imgobject.size.height * part);   byteptr picturedata = (byteptr)malloc(rcmask.size.width * rcmask.size.height * 4);  cgcontextref picturecontext = cgbitmapcontextcreate(picturedata, rcmask.size.width,              rcmask.size.height,8, rcmask.size.width * 4,cgimagegetcolorspace(imgobject.cgimage),              kcgimagealphapremultipliedlast | kcgbitmapbyteorder32big);   cgcontextcliptomask(picturecontext, rcmask, imgmask.cgimage);  cgimageref imginrect;  imginrect = cgimagecreatewithimageinrect(imgobject.cgimage, rcobject);  cgcontextdrawimage(picturecontext, rcobject, imginrect);  cgimagerelease(imginrect);  ***imgresult = [uiimage imagewithcgimage:cgbitmapcontextcreateimage(picturecontext)];***   cgcontextrelease(picturecontext);  free(picturedata);  return imgresult; } 

imgresult = [uiimage imagewithcgimage:cgbitmapcontextcreateimage(picturecontext)]; 

you create cgimage, pass uiimage factory method, , forget it. you're leaking cgimage.

do instead:

cgimageref cgresult = cgbitmapcontextcreateimage(picturecontext); if (cgresult) {     imgresult = [uiimage imagewithcgimage: cgresult];     cgimagerelease(cgresult); } 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -