Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: BufferedImages not garbage collected -- any suggestions?



Michael Ellis wrote:

when I check the type of the returned objects in the debugger, I find
that I am receiving "apple.awt.OSXImage" instances, not the
BufferedImage instances I expected.  I then wrote a little test
program, and I found that "apple.awt.OSXImage" instances are returned
by the java.awt.Toolkit.createImage() method.

So, perhaps we have an explanation here.  I've found that flush()ing
my images made a big difference in my program's ability to reclaim
memory, but, as we thought we were using BufferedImages, we were
unable to determine why this action would matter for that particular
java.awt.Image variant.  In fact, it would seem that this  library
method I am using is not returning the promised BufferedImage, but
instead a different Image subclass.  Hence, the flush() method is
useful for the actual instance returned.

I suppose the lesson learned here is that if you only know you're
going to acquire some generic java.awt.Image subclass, go ahead and
make arrangements to flush() it.

I would still think it reasonable to expect an OSXImage to clean up after itself automatically. However, OSXImage does not implement flush -- that is done by its base class, sun.awt.image.ToolkitImage. ToolkitImage does not implement finalize. I think Apple could fix the problem by implementing finalize in OSXImage, and having it call flush (before calling super.flush). I cannot see any way to detect when an Object is about to be collected via an external mechanism (e.g. a listener, Reference object, etc.), so we can't hack in a fix externally, it needs to be built in to the ToolkitImage class tree.

We have seen the flush issue on other platforms than OS X, so I think
the "proper" fix needs to be put in by Sun, by implementing finalize
on ToolkitImage to force a flush before GC reclaims the image. Has
anyone reported this to Sun?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.