I have an application, which allows to load CAD files, visualized with jReality. If one of these files is closed, the allocated memory isn't released. I examined the problem and came to the conclusion, that the ViewerApp class doesn't release the memory. Could this be correct or is there an official way to release the memory, allocated by jReality?
I broke it down to this little example. You can see, that the memory grows from 0 MB to 19 MB. The Garbage Collector can free up 2 MB, so that it ends up in 17 MB.
If the ViewerApp class isn't instantiated, the memory goes up to 17 MB and can completly be removed by the Garbage Collector.
Thanks and best regards, Joe
Code
Code: Select all
import java.awt.Component;
import javax.swing.JFrame;
import de.jreality.geometry.Primitives;
import de.jreality.scene.SceneGraphComponent;
import de.jreality.ui.viewerapp.ViewerApp;
public class SimpleViewer {
private static void printMemoryUsage(String message){
long memoryMaximum = Runtime.getRuntime().maxMemory();
long memoryTotal = Runtime.getRuntime().totalMemory();
long memoryUsed = memoryTotal - Runtime.getRuntime().freeMemory();
System.out.println(message + ": " + (memoryUsed >> 20) + " / " + (memoryTotal >> 20) + " / " + (memoryMaximum >> 20) + " MB");
}
public static void main(String[] arguments){
printMemoryUsage("Before creating geometry");
SceneGraphComponent sceneGraphComponent = new SceneGraphComponent();
sceneGraphComponent.setGeometry(Primitives.torus(3.0, 5.0, 200, 200));
ViewerApp viewerApp = new ViewerApp(sceneGraphComponent);
printMemoryUsage("After creating geometry");
sceneGraphComponent = null;
viewerApp.dispose();
viewerApp = null;
System.gc();
try {
Thread.sleep(5000);
} catch(Exception exception){
exception.printStackTrace();
}
printMemoryUsage("After garbage collection");
}
}
Code: Select all
Before creating geometry: 0 / 4 / 63 MB
scene root is root
After creating geometry: 19 / 23 / 63 MB
After garbage collection: 17 / 31 / 63 MB
Code: Select all
Before creating geometry: 0 / 4 / 63 MB
After creating geometry: 17 / 23 / 63 MB
After garbage collection: 0 / 23 / 63 MB