views:

50

answers:

0

Same problem as this guy

I'm trying to use CGBitmapContextCreateImage() or UIGraphicsGetImageFromCurrentContext(), but they leak badly, even if I don't do anything in the context. When I run this in a UIView subclass, before setNeedsDisplay:

UIGraphicsBeginImageContext(CGSizeMake(320, 264));
// Optional drawing code here, but still leaks, even with zero drawing      
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Allocations and Activity Monitor show my allocs pumping up by nearly a megabyte each time. I've done this using CGBitmapContextCreate too, both with and without a data pointer, and it always leaks 664KB from a CoreGraphics zone_calloc. I've tried over-releasing the images and context, using autorelease pools, freeing the data pointer...nothing stops it.

What's more confusing is, if I put this code into its own program, or move it around my app, it stops leaking. e.g., if I drop it in at the beginning of the view's init method, it doesn't leak. Depending on where I create the context, could something be grabbing the data pointer and never letting go?

At this point I don't know what to do with the project. Drawing the image is required but I can't just ignore the huge leaks. Are there any low-level ways to draw an image from a context, where I could have control over the memory?