ios - Mysterious memory management issue in Core Graphics -
here method use in category on uiimage resize it. works seems in method (i not 100% sure it's in there) amassing memory. not expert , quite difficult me trace down cgcontext function using instruments.app
http://bytolution.com/instruments_scrnsht.png
- (uiimage *)cropwithsquareratioandresolution:(cgfloat)resolution { uiimage *sourceimg = (uiimage*)self; cgsize size = [sourceimg size]; int padding = 0; int picturesize; int startcroppingposition; if (size.height > size.width) { picturesize = size.width - (2.0 * padding); startcroppingposition = (size.height - picturesize) / 2.0; } else { picturesize = size.height - (2.0 * padding); startcroppingposition = (size.width - picturesize) / 2.0; } if (resolution == 0) resolution = sourceimg.size.width; cgrect croprect = cgrectmake(startcroppingposition, padding, picturesize, picturesize); cgrect newrect = cgrectintegral(cgrectmake(0, 0,resolution, resolution)); cgimageref imageref = cgimagecreatewithimageinrect([sourceimg cgimage], croprect); // build context that's same dimensions new size cgcontextref bitmap = cgbitmapcontextcreate(null, newrect.size.width, newrect.size.height, cgimagegetbitspercomponent(imageref), 0, cgimagegetcolorspace(imageref), cgimagegetbitmapinfo(imageref)); cgcontextsetinterpolationquality(bitmap, kcginterpolationhigh); cgcontextdrawimage(bitmap, newrect, imageref); cgimageref newimageref = cgbitmapcontextcreateimage(bitmap); uiimage *newimage = [uiimage imagewithcgimage:newimageref scale:1.0 orientation:self.imageorientation]; // clean cgcontextrelease(bitmap); cgimagerelease(newimageref); cgimagerelease(imageref); return newimage; }
on screenshot above can see how memory usage gets higher every image taken (and being processed method). btw using sdk 7 , arc.
how can rid of leak or whatever is? needs dealloced (or did miss in code)?
Comments
Post a Comment