English 中文(简体)
Java 3D Memory Leak
原标题:

I have a large scene graph in Java 3D consisting out of a Group which contains around 3500 Switches, each containing a Shape3D and a Group, the latter contains two more Shape3Ds.

The reason for this setup is that each of the 3500 Switches must be able to be either completely hidden or have either of its two children visible.

The problem occurs when I try to modify the geometry of the two Shape3Ds in the Group in a Switch. I have attempted the following:

  • Change Group to BranchGroup. When the geometry needs to be changed I detach the BranchGroup and create a new one, with updated geometry, to replace it. Leaks huge amounts of memory. For example, the initial memory usage will be around 100 MB. A change in geometry later it is around 400 MB.

  • Make the Geometry editable. When the geometry needs to be changed I edit it directly. Leaks huge amounts of memory. Similar to above.

  • Make the Geometry editable, but by reference. When the geometry needs to be changed I call updateData(...) with an appropriate GeometryUpdater, which then does its thing. Leaks memory.

  • Recreate the entire scene graph. When the geometry needs to be changed, I detach the entire scene graph, recreate it from scratch using the updated geometry, and attach the new scene graph. Leaks memory.

I can t help but feel there is something basic about Java 3D memory management that I m missing and that is common to all my attempts.

The speed of changing the geometry is not an issue, as it is a rare occurence. The memory problem, however, is serious.

最佳回答

It s usually misleading to use tools that monitor memory at the operating system level to deduce memory leaks in a Java Virtual Machine. The JVM has its own ideas on when it is efficient to claim and reclaim memory.

If you could explain how you are observing the memory leak and why it is a serious problem then it might be easier to answer your question.

  • How are you measuring memory usage?
  • If you force a garbage collection and output the memory usage do you still see the leak?
  • Does the memory problem cause a java.lang.OutOfMemoryError ?

You might also be interested in this question: https://stackoverflow.com/questions/1716597/java-memory-leak-detection-tools

问题回答

Attach to your program with visualvm (available as jvisualvm binary in the JDK), and use the profiler to get an idea where your memory goes.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签