Hello,
Im seeing some very concerning issues with memory “leaks” in the JMonkey engine. We first started seeing our game take little “jumps” periodically, and weve traced it down to a delay in the frame when the JVM garbage collection occurs. So I went to a bare-bones SimpleApplication and am seeing the same issue. With a framerate of 100, Im seeing garbage collection happen up to every 70ms!!! Im thinking this should definitely not be happening in a simple application, and its causing display issues that make our game look very bad!
In below output, first number is free memory, 2nd is size of memory change, 3rd is time since last memory change.
Here we see some new memory being added every 10ms:
UsedMem 21617.836 memdiff 985.25 timediff 10
UsedMem 22603.008 memdiff 985.1719 timediff 9
UsedMem 23588.258 memdiff 985.25 timediff 9
UsedMem 24573.508 memdiff 985.25 timediff 10
UsedMem 25558.758 memdiff 985.25 timediff 10
UsedMem 26543.93 memdiff 985.1719 timediff 10
In the code segment below, comment/uncomment the “if” statements below “LOOK HERE” to see how often we garbage collect:
UsedMem 1918.3828 memdiff -8324.211 timediff 73
UsedMem 1886.3828 memdiff -8436.211 timediff 74
UsedMem 1854.3047 memdiff -8436.289 timediff 74
UsedMem 1854.2422 memdiff -8404.352 timediff 72
UsedMem 1886.3828 memdiff -8372.211 timediff 74
Also note, if you comment out the call to printCheckMem and uncomment the freeMemory print, youll see it drastically changing constantly.
Thanks in advance!
(Note: Im current to 3/6/2011 nightly build)
[java]package memtest;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.math.ColorRGBA;
import com.jme3.system.AppSettings;
import com.jme3.system.JmeContext;
import java.util.logging.Level;
import java.util.logging.Logger;
/** Sample 1 - how to get started with the most simple JME 3 application.
- Display a blue 3D cube and view from all sides by
- moving the mouse and pressing the WASD keys. */
public class Main extends SimpleApplication {
public static void main(String[] args){
Main app = new Main();
Logger.getLogger("com.jme3").setLevel(Level.WARNING);
Logger.getLogger("de.lessvoid.nifty").setLevel(Level.OFF);
AppSettings mAppSettings = new AppSettings(true);
mAppSettings.setFrameRate(100);
app.start(JmeContext.Type.Display);
}
@Override
public void simpleInitApp() {
}
@Override
public void simpleUpdate(float tpf) {
printCheckMem("UsedMem");
// System.out.println(Runtime.getRuntime()
// .freeMemory());
}
private static float oldUsedMem = 0;
private static float newUsedMem = 0;
private static float kb = 1024;
private static long oldSysTime = System.currentTimeMillis();
private static long newSysTime = 0;
public void printCheckMem(String label) {
newUsedMem = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime()
.freeMemory()) / kb;
///// LOOK HERE
if (Math.abs(newUsedMem - oldUsedMem) > 0)
// if ((newUsedMem - oldUsedMem) < 0)
{
newSysTime = System.currentTimeMillis();
System.out.println(label + " " + newUsedMem + " memdiff "
- (newUsedMem - oldUsedMem) + " timediff " + (newSysTime - oldSysTime));
oldSysTime = newSysTime;
}
oldUsedMem = newUsedMem;
}
}[/java]