Memory Leak "Jme Terrain Thread"

Hi there,

I’m having trouble getting rid of this memory leak and it seems like Im killing these terrains completely but perhaps I may not be.

I switch between 2 scenes one has one terrain, the second has 3 terrains.

Every time I switch scenes the “jme terrain thread” remains and adds threads consistently.

This is definitely the cause of my memory leak.

On pc the memory is negligible about 3mb per scene switch 60 mb if you die 20 times or beat the whole game without closing.

But unfortunately on Android, it lowers performance until out of memory crash

Is this due to me not dereferencing properly and the terrain not being garbage collected?

Or is this something that is seperate?

Also can I force destroy these terrains somehow if it is a dereference problem?

Ive written a simple test case (the models I load are the ones in my game the terrains are made in the terrain editor)

http://hastebin.com/ekogucivim.avrasm

Here is an image of the results. As you can see many threads run but are not removed even when setting the Node containing the terrain to null

As well as detaching all children from the rootNode

Hm from my knowledge the cleaning logic looks correct, and should work correctly.

Can you test if including a System.gc() in the cleans results in the stuff being properly cleaned?

I remember this from a previous discussion. I believe it’s as a result of the LOD control creating a thread of its own. So each time you add a LOD control, you get a thread. If I recall - @sploreg added a .setExecutor() method to the LOD control so you could set a threadpool of your own for better management. I can’t remember if that commit was released on the stable branch…

Running the Garbage Collector has no effect and still has the memory leak.

EDIT: SOLVED

Solved using reflection thanks to @Empire_Phoenix

http://hastebin.com/gajatizagi.coffee

@jayfella

You were right about the LOD thing. It isnt implemented yet so I had to access the protected field and shut it down myself.