Re: CIImage (TIFFRepresentation) memory leak
Re: CIImage (TIFFRepresentation) memory leak
- Subject: Re: CIImage (TIFFRepresentation) memory leak
- From: Rob Keniger <email@hidden>
- Date: Tue, 11 Mar 2008 13:46:27 +1000
On 11/03/2008, at 6:03 AM, email@hidden wrote:
I narrowed this down by removing the filters, and the leak is still
there. And what a leak! Everytime I draw the view the memory usage
increases with the size of the drawn image. Yet this exact same code
is used in the Core Image Programming Guide. So I figure it's a bug in
Core Image. But how can I avoid it?
I had problems with this too, and I use a workaround I found somewhere
where you render to a CGImageRef in the context of the current window.
Here's a dump of the code:
//theImage is an existing NSImage
CIImage *outputImage = [CIImage imageWithData:[theImage
TIFFRepresentation]];
//to draw the image processed by Core Image, we need to draw into an
on-screen graphics context
//this works around a bug in CIImage where drawing in off-screen
graphics contexts causes a huge memory leak
//get the current window's graphics context so that we have an on-
screen context
//usually we would use any view's window but generically you can just
ask for the main window
CIContext *ciContext = [[[NSApp mainWindow] graphicsContext] CIContext];
if(ciContext == nil)
{
NSLog(@"The CIContext of the main window could not be accessed.
Bailing out of the image creation process.");
return;
}
CGAffineTransform transform;
transform = CGAffineTransformMakeTranslation(0.0,[outputImage
extent].size.height);
transform = CGAffineTransformScale(transform, 1.0, -1.0);
outputImage = [outputImage imageByApplyingTransform:transform];
//render the CIIimage into a CGImageRef in the on-screen context
CGImageRef cgImage = [ciContext createCGImage:outputImage fromRect:
[outputImage extent]];
// Draw the CGImageRef into the current context
if (cgImage != NULL)
{
CGContextDrawImage ([[NSGraphicsContext currentContext]
graphicsPort], [outputImage extent], cgImage);
CGImageRelease (cgImage);
}
HTH
--
Rob Keniger
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden