Skip to main content

[JAVA3D-INTEREST] ImageComponent2DRetained Memory Usage

3 replies [Last post]
Anonymous

Hello all,

I am working with an application that needs to create and use many Textures
during runtime, which continually get added and removed from the scenegraph.
For each texture there is an ImageComponent2D, and therefore an
ImageComponent2DRetained (although there are many of these, about 3:1, for
each image component, but that is another issue).

After a while, I found that my application consumes all available memory.
Running it through the profiler I found that the ImageComponent2DRetaineds
are getting stuck in the Finalizer list waiting for finalization. Looking at
the code, it is true that ImageComponent2DRetained does indeed have a
finalize method used to release the D3D texture. Due to the high cost of
allocation and GC with finalizers
(http://www-106.ibm.com/developerworks/library/j-jtp01274.html) is there a
better way to allow the ImageComponent2DRetained to release its texture?
What happens if the finalizer is never called (as could be the case
according to the java spec)?

The major problem is that each ImageComponent2DRetained maintains its
reference to the original texture image (which is 256 x 256 x 4 in my case)
while in the finalizer list of the GC, causing quite a memory problem. There
does not appear to be a way to force the ImageComponent2DRetained to release
its reference to the image data while waiting for finalization. Also, object
pooling of the ImageComponent2D objects does not help since setting a new
image on it appears to force the creation of another
ImageComponent2DRetained. Due to the possible short lifespan of an
ImageComponent2DRetained, a finalizer does not seem appropriate.

Although I am not completely familiar with the finalizer thread, I found
that increasing the thread priority of the allocating thread helped to force
finalization on the pending objects, however this is not a preferred
solution.

Does anyone have a suggestion, or a comment on what can be done about the
use of finalizers in ImageComponent2DRetained (and possibly elsewhere in
J3D?).

Thanks,
-mike

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
For additional commands, e-mail: interest-help@java3d.dev.java.net

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
pepe
Offline
Joined: 2003-06-10

Hello.
Maybe instead of recreating new textures, you could use update mechanisms, and only update the texture contents?
If that does the job, have a look at:
javax.media.j3d.ImageComponent2D.setSubImage()
and
javax.media.j3d.ImageComponent2D.updateData()

I've been using them for a mini painter on 3d objects, thus had textures constantly changing, and it worked fine.

Anonymous

Hello Mike!

We do currently have the exact same problems as you described. On the one hand i'm glad to have found s.o. who experiences the same phenomenon, on the other hand i'm afraid, that there's doesn't seem to be a solution, yet.
However, since your post is now nearly a month old i wonder, if you have found a solution; we don't even have a clue.
If so i would be very grateful if you could describe it here. Even if it is not a very nice solution. Everyhing is welcome, as this problem is filling our memory until after a couple of minutes the system is too slow to continue working.

Thanks a lot!
Sascha H

Mike Pilone

Hi Sascha,

It is funny that you brought this up today. I was planning on filing a bug
report for it when I got into the office.

My current work around is to reuse the buffered images in the image
components. Luckily the ImageComponent2D and the retained objects are fairly
small, so keeping many of them around on the finalizer queue is not too much
of a problem. Most of the memory is being consumed by the image reference
that they maintain.

For my application all of the textures are 256x256, so reusing the
BufferedImages works well. I think you could do the same thing with varying
size images, but you would need to be a little more creative with your
DataBuffer size and BufferedImage setup.

As for the actual image pool, I use a simple ArrayList with WeakReferences
which will allow the garbage collector to clean up the images if the
finalizer ever does run.

I hope that helps. I'll submit a report sometime this morning.

-mike

-----Original Message-----
From: java3d-interest@javadesktop.org
[mailto:java3d-interest@javadesktop.org]
Sent: Thursday, July 22, 2004 4:04 AM
To: interest@java3d.dev.java.net
Subject: Re: [JAVA3D-INTEREST] ImageComponent2DRetained Memory Usage

Hello Mike!

We do currently have the exact same problems as you described. On the one
hand i'm glad to have found s.o. who experiences the same phenomenon, on the
other hand i'm afraid, that there's doesn't seem to be a solution, yet.
However, since your post is now nearly a month old i wonder, if you have
found a solution; we don't even have a clue.
If so i would be very grateful if you could describe it here. Even if it is
not a very nice solution. Everyhing is welcome, as this problem is filling
our memory until after a couple of minutes the system is too slow to
continue working.

Thanks a lot!
Sascha H.
---
[Message sent by forum member 'Sash' (Sash)]

http://www.javadesktop.org/forums/thread.jspa?messageID=18475&#18475

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
For additional commands, e-mail: interest-help@java3d.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
For additional commands, e-mail: interest-help@java3d.dev.java.net