memory - imageWithCGImage make app crashed -
my project automatic reference counting, when use cgbitmapcontextcreateimage , uiimage's method imagewithcgimage, happened. wrote testing code, when code running, memory increased until app crashed.
the device:
[16g, ipad2, retina]
the code:
(uiimage*) createimagebyimage:(uiimage*)img { cgsize imgsize = img.size; imgsize.width *= [uiscreen mainscreen].scale; imgsize.height *= [uiscreen mainscreen].scale; cgcolorspaceref space = cgcolorspacecreatedevicergb(); cgcontextref ctx = cgbitmapcontextcreate(nil, imgsize.width, imgsize.height, 8, imgsize.width * (cgcolorspacegetnumberofcomponents(space) + 1), space, kcgimagealphapremultipliedlast); cgcolorspacerelease(space); cgrect rect; rect.origin = cgpointmake(0, 0); rect.size = imgsize; // here bypass transformation cgcontext cgcontextdrawimage(ctx, rect, img.cgimage); cgimageref cgimage = cgbitmapcontextcreateimage(ctx); cgcontextrelease(ctx); uiimage* image = [uiimage imagewithcgimage:cgimage scale:[uiscreen mainscreen].scale orientation:uiimageorientationdown]; cgimagerelease(cgimage); return image; } the caller:
uiimage* baseimg = [uiimage imagenamed:@"corkboard.jpg"]; // big image,e.g. 1024*768 (int = 0; < 100; i++) { uiimage* tempimg = [self createimagebyimage:baseimg]; tempimg = nil; } baseimg = nil; is there can explain? waiting help!!!
another thing: in code, if replace
[uiimage imagewithcgimage:cgimage ....]; with
[uiimage imagewithcgimage:img.cgimage ....]; the error disappeared! function changed, not met original demand!
Comments
Post a Comment