Memory and ParticleEmitters


I ran on some memory trouble with my game Chaos. Searching for some memory leaks, I ended up with these lines of simple code. (simply flood some emitter on the center of the screen, each 0.15s)

I’m wondering what I’m doing wrong with this (or not doing at all). Lines below generated some abused memory usage when letting the app running. Initial memory usage (processus) is 90mB and 20min later, 280mB… I fear letting this running for 1 hour long… !
I’m using window7.

Someone could help with this ?

public class TestMemory extends SimpleApplication {

    private Node j;
    private float time = 0.15f;

    public static void main(String arg[]) {
        TestMemory app = new TestMemory();

    public void simpleInitApp() {
        j = (Node) this.getAssetManager().loadModel(Models/emitter.j3o);

    public void simpleUpdate(float tpf) {
        if (time > 0) {
            time -= tpf;
        } else {
            for (Spatial e : j.getChildren()) {
                ((ParticleEmitter) e).emitAllParticles();
            time = 0.15f;

emitter.j3o is a basic JME emitter?
Or is it particular?

I’m trying to run the test

Also,what happens if you set like Xmx128mb for example? doe it crash with OOM or does the garbage collection does its work?

Hello Nehon,

Thanks for your time.

I do not use Xmx param I’ll test with this and emitter.j3o is contains 3 emitters with 3 different material using 256x256 texture. You already seen these kind of FX on some Chaos vids. Not such very Advanced effect.

By the away, I’ve run the same test, replacing emitter by an AudioNode, not streamed, fired with playInstance() function. The result is the same. Constant memory consumption.
I’ve test with and without -d64 param. Memory trouble seems to be more signifiant with.

mhh…ok with a basic emitter the memory goes slightly up to 50mb in 5 minutes, then it collects and get back to around 10.
Maybe there are some unnecessary objects created, but that doesn’t look abnormal to me.

I ran it with the netbeans profiler, you should try. It gives more in depth informations.

yeah but I’m afraid of memory because if 1 emitter can grab 50mB in 5 minute, how about 20 ? + 1 sound per emitter fired ?

Btw, I’ll give a try to profiling.

The point is that garbage collection won’t kick in until a certain max memory percentage is reached. So if you add 20 emitters, it will reach 50 meg faster before dropping back down again. As long as you aren’t hitting the heap so fast as to force a full GC then you should be ok.

But you also might consider alternatives, because it seems like particle emitters were not meant to be used in the “emit all particles every 0.15 seconds” kind of way.

I’ve tried with Xmx param and it seems to calm down memory usage.

I wasn’t aware (my bad…) of the relation between gc and max memory. I used to think that gc was randomly ran to clean up un-referenced objets, regardless anything else.

I agree with you pspeed, this test is what it is mean to be. A test :slight_smile:
I do not use emitter this way but it is good to simulate a melee of 10 to 20 toons.

Thank you both for replies.

Well, still it can’t hurt to have a look if we can somehow reduce the garbage generated by this method.
I’ll keep you informed