I have a problem with creating new and deleting old TerrainQuad classes. The idea is that I create one such class with texture and heightmap, and later I would like to destroy this instance of TerrainQuad (to recover memory) and create new one with new texture and heightmap. Both images (texture and heightmap) are 2048x2048 pixels as I am interested in detailed 3d map model.
I’m creating terrain in this way:
[java]mTerrain = new TerrainQuad(“terrain”, 65, heightmap.getSize(), heightmap.getHeightMap());[/java]
Later I add LOD control, material, scale, etc.
Then, when I want to create a new TerrainQuad I call the following function:
private void clearData()
mTerrain.forceRefresh(true, true, true);
mTerrain = null;
catch (Exception e)
So whenever I create TerrainQuad again, everything should be fine. But isn’t. Although I tried to set everything to null in mTerrain, there are still quads and patches in the memory (I used VisualVM to dump heap to read this information). As a result, after a few changes of the 3d map, I get OutOfMemoryError.
For better visualization of this problem: some numbers of instances after a few changes of the terrain:
floats: 4992 (53.8% size of heap -> 8744 (68.4%) -> 12496(72.2%)
quads: 1024 -> 2048 -> 3072
patches: 341 -> 681 -> 1021
In Task Manager after lunching the application it uses about 850MB, but after one change it jumps to more than 1GB and it crushes when reaches 1.4-1.6 GB.
So my question is: is there any way to have access to those unused fields to delete them? Garbage Collector doesn’t seem to be doing it’s job well in this case. Or is there any other way to set new heightmap to the terrain (creating two ‘for’ loops to use setHeight method doesn’t sound good for me, besides there might get some unwanted artifacts)?
In the end I will also add, that setting LOD control to null and disabling it, so later it is possible to start fresh instance for new terrain, doesn’t stop “jME Terrain Thread”. Again, thanks to Thread Dump in VisualVM I was able to find it. Fortunately, it is possible to create one LOD Control and just set new terrain there.
If there was any topic related to this problem: sorry, as you can see, I am brand new on this forum
PS. I tried also to create a loop to search for all children of children of TerrainQuad and remove them from parent one by one, but it still doesn’t work.
The error output is the same as in the topic http://hub.jmonkeyengine.org/forum/topic/application-crashes-in-sdk-but-not-out-of-sdk/, but I am sure that I use 64-bit JVM, as this one is the only one set in my Eclipse (yes, I use this IDE). Anyway, if I export the project to runnable jar, the error still exists.