Re: NSImage TIFFRepresentation memory leak
Re: NSImage TIFFRepresentation memory leak
- Subject: Re: NSImage TIFFRepresentation memory leak
- From: Roland Torres <email@hidden>
- Date: Fri, 1 Dec 2006 12:03:49 -0800
On Dec 1, 2006, at 10:09 AM, Shawn Erickson wrote:
On 12/1/06, Roland Torres <email@hidden> wrote:
I call TIFFRepresentation since it's the only way I know to write
the NSImage out
to a file, but this is called in only one place, and the leak only
occurs when I do
that. ... I guess I'll have to live with it for now, unless I can
find another way to
generate an image file from the NSImage.
How are you creating you NSImages? What is the source of their
image data?
NSImages are in a way an abstraction of a displayable image while the
real image data in contained in an image rep which NSImage may have
one or more of. If your images are bitmap based then look at using
-[NSBitmapImageRep representationUsingType:properties:] to request an
NSData instance with the bitmap data in a particular image format. You
can get the image rep from the NSImage... however it isn't clear how
you are creating your images so it isn't clear what reps they will
contain. Also you can draw an image into a NSBitmapImageRep and then
ask for the format of your choice... or use ImageIO (part of
CoreImage).
Also do you know what memory or object is leaking? It would help to
figure out what it is... I have a feeling it is something related to
the CGL context that is getting created in the process of converting
the image data into TIFF format. I have seen some reports go by on the
quartz and opengl lists of contexts created by CGLCreateContext then
later destroyed by CGLDestroyContext resulting in a leak.
Basically, I'm starting with a CIFilter. Then, (error checking
removed for clarity):
NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
CIImage *ciImage = [filter valueForKey:@"outputImage"];
NSCIImageRep *ciImageRep = [NSCIImageRep
imageRepWithCIImage:ciImage];
NSImage *nsImage = [[NSImage alloc]init];
[nsImage setCachedSeparately:YES];
[nsImage setCacheMode: NSImageCacheNever];
[nsImage addRepresentation: ciImageRep];
[self performSelectorOnMainThread:@selector(writeToDisk:)
withObject:nsImage
waitUntilDone:YES];
[nsImage release];
[pool release];
. . .
-(void)writeToDisk:(NSImage *)nsImage
{
// following steps done on main thread
NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
NSData *nsData=[nsImage TIFFRepresentation]; // <-- leaks here
[nsData writeToFile:filespec atomically:NO];
[pool release];
}
Is there an easier way to go from a CIImage to an image file? This
seems quite a roundabout way.
Roland
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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