• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Memory Problem with Java 3D  RSS feed

 
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
 
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!