Memory Management

Hello,



I have a two questions about JME, JVM and garbage collection. I analyzed the following scenario:



Step 1 Startup:

TaskManager: 170MB

Memory Analyzer: 4MB



Step 2 Adding 100000 geometries to the node “map”:

TaskManager: 820MB

Memory Analyzer: 500MB



Step 3 Removing the 100000 geometries again by calling map.detachAllChildren(), map.updateGeometricState():

TaskManager: 820MB

Memory Analyzer: 11MB




  1. How can I minimize the memory which the JVM itself takes. As you can see in all steps there are huge differences in what the TaskManager displays and what the Memory Analyzer displays.


  2. Looking at Step 3: why is the garbage obviously collected, but the memory not freed?





    Many thanks in advance!



    Gatsu

The assetManager caches the loaded assets up to the jvm maximum memory amount. To clear the cache, call DesktopAssetManager.clearCache().

Suns jvm does not free once needed ram.(At least not the 6 , maybee in the 7)

Thanks for the information. ClearCache() doesnt do anything to my memory consumption, but im already satisfied that this is normal behaviour.

Hoping for an answer on question 1 now :smiley:

you can specify command line options for the jvm, an example is given in the project properties.

http://download.oracle.com/javase/1.4.2/docs/tooldocs/windows/java.html

Two things… I’ve definitely seen Java give memory back to the system since JDK 5… though it’s hit or miss. I still use the task manager to track this. I’ve seen application go from using 1 gig back down to 400 meg a time or two.



However, the thing that throws the numbers off between the JVM’s view of its heap and the system’s view of its heap is the direct memory that is allocated for meshes, etc… the stuff that needs to go to OpenGL. This is not counted in the JVM’s visible memory (from Java) but it is memory still held by the application until GC gets around to freeing it… in its own good time.



I’m half looking for general solutions to this issue as well since Mythruna churns through direct memory and the garbage collector doesn’t always keep up so well. In my case, my final plan is to reuse the buffers when I get to that kind of optimization.