Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Memory Problem with Java 3D

 
eve agostini
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm using an Offscreen Canvas to create an image with Java3D: I render offscreen on an instance of ImageComponent2D, created with a BufferedImage. I need to do that again every time something changes in the model. The problem is that the allocated memory increases every time I render the offscreen canvas for a new rendering, but it never decreases. After a while a get an Out Of Memory exception. If I look at the heap dump there are a lot of ImageComponent2D, ImageComponent2DRetained and RenderedImage objects, which were not deleted.

Here is the piece of code that perform the offscreen rendering:



Thanks for any help
Eve
 
August Lammersdorf
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, in my experience it's not easy to get rid of a BufferedImage. In the Java 3D Scala sample program ScCharacterCube (http://www.interactivemesh.org/testspace/j3dmeetsscala.html) it seems to work. Following tips might be helpful:

- Cache and reuse the BufferedImage instance as long as its size or type doesn't change.

- Prevent ImageComponent2D from copying image data by using this constructor
'new ImageComponent2D(myFormat, myWidth, myHeight, true, true)' which creates an instance in 'byReference' and 'yUp'-mode.

- Don't be shy of running the garbage collector (System.gc()) as soon as references are set to null.

Even if the sample is written in Scala see how the object/subclass 'offCanvas3D' in the source code of 'CharacterCubeUniverse.scala' is designed. It includes also the def/method 'flipImageY(bImage: BufferedImage)' to flip your image into 'yDown'-mode.

August, InteractiveMesh
 
eve agostini
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the advices! Actually I'm giving a try to another 3D lib at the moment, but I'll try to modify my Java3d test following your suggestions.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!