views:

180

answers:

0

I'm traversing the view hierarchy of the camera view and grabbing the image from the view like this:

CGImageRef img = (CGImageRef)[cameraView imageRef]; // undocumented api...

I then run it through a transformation to rotate it back to the correct orientation. Once in the correct orientation, I merge another image on top of it with a transparent background.

My problem is that my application jumps to 18MB of used ram when the images are merged. Then if I save this image to the Photo Library, while saving my the image, memory jumps again to almost 30MB. At this level of memory usage, SpringBoard sometimes force quits my application.

When the photo is finally saved out, the memory usage drops back to normal. But I did find that if I use this to grab the photo that's to be merged

[UIImage namedImage:@"imagefile"];

saving the photo will leak memory somewhere in the foundation. I've changed those calls to this instead

[UIImage initWithContentsOfFile:<fullpath>];

and those memory leaks seem to be gone now.

Has anyone had trouble like this? If so, what did you do to fix the problem?

As an aside, in the method where I merge the two images, I create a local release pool so that I can control the autorelease memory for the image copy.

NSAutoreleasePool *localPool = [[NSAutoreleasePool alloc] init];

....

UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext();
[imageCopy retain];

UIGraphicsEndImageContext();

[localPool drain];

Any help would be greatly appreciated!