Re: NSImage TIFFRepresentation memory leak
Re: NSImage TIFFRepresentation memory leak
- Subject: Re: NSImage TIFFRepresentation memory leak
- From: Daniel Jalkut <email@hidden>
- Date: Fri, 1 Dec 2006 09:30:48 -0500
I just caught sight of this thread, and went back to read Roland's
original description. I have seen what appear to be NSImage-related
leaks in a multi-threaded environment, too.
Roland, I see that you point out the "TIFFRepresentation" call is
being made on the main thread, but what of all the other use of the
NSImage? All on the main thread, too? I suspect you're using the
same NSImage in more than one thread, and this is messing up the
NSImage caching mechanism. In my experience NSImage leaks when given
the opportunity to try to cache on more than one thread.
It's been a long time but in my case I came to the conclusion that I
would work around the problem by turning off caching on the images in
question. Perhaps it was a brute-force way of fixing the problem,
but it did the trick and I didn't notice a major performance hit.
This is a simple category method I added to NSImage:
- (void) makeThreadSafe
{
[self setCachedSeparately:YES];
[self setCacheMode:NSImageCacheNever];
}
I basically call [theImage makeThreadSafe] as quickly as possible
after creating instances of any NSImage in the app.
Hope this helps, at least to know that you're not alone :) Perhaps as
a test you could try the above technique just to see if we're talking
about the same phenomenon.
Daniel
On Dec 1, 2006, at 8:06 AM, j o a r wrote:
On 1 dec 2006, at 09.33, Hidetomo Katsura wrote:
FYI, this is a textbook case of an OS leak. you (or at least i)
can easily tell from the backtrace. you are only responsible for
releasing a reference that's returned by a method or function.
just file a bug and move on. if it's a significant leak, you have
to come up with a workaround.
in this case, a reference returned by CGLCreateContext (or
allocate_context. it doesn't matter) is the leak, and it was never
returned to you since -[NSImage TIFFRepresentaion] only returns an
autoreleased NSData object (not a CGLCreateContext). obviously,
you can't directly release a reference returned by
CGLCreateContext since you don't even have access to it.
in short, if you didn't create (allocate, copy, or retain) it,
it's not your leak.
Based on the data presented in this thread so far I would not agree
that your claim is necessarily true.
ObjectAlloc shows backtraces to things that are allocated, but
that's not the same thing as leaked.
If the piece of data that is allocated in this backtrace is still
live, that is most likely because its "owner" has not released /
freed it yet. Note that the "leak event" is typically not the same
thing as the allocation event!
Presented with something that could be either [1] a memory leak in
a framework, or [2] a memory leak in your code, you should always
suspect your code - Unless the evidence to the contrary is
overwhelming.
In this case we don't even know what's being leaked - is it opaque
malloced data? It should be of primary interest to see if the
NSData instances returned from "-TIFFRepresentation" are leaked or
not. This, and many other similar points of data, is still unknown.
The best thing would of course be if this proposed leak could be
isolated in a small sample program, and posed for others to have a
look at.
I'm not saying that you're necessarily wrong, only that I don't
think we have enough information to assert that you're right.
j o a r
_______________________________________________
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:
sweater.com
This email sent to email@hidden
_______________________________________________
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