Heap size keeps increasing using physics, help?

Hey, I’ve ran into some fps dropping issues with my game.



I’ve concluded that its related to the generation of projectiles, and most likely is

caused by some kind of memory leak, but I’m unable to figure out what more specificly is causing it.



When having a high fire rate of projectiles (spawning many per second)

this is what happens when I keep firing them.

http://puu.sh/LRzs.png



I’ve been running the profiler to try to figure the heap peaks out but with no success.



I’m thinking it might be related to the physics space not releasing some objects,

as I do not have the issue if I dont attach them to the physics space.



Right now, this is what I do when a collision occurs between a projectile and another object,

alternatively if it has travelled further than its range.



This is from the ProjectileCollider.class handling collisions

The kinetic controller is ProjectileControl.class

proj is the projectile instance (a node)

[java]private void remove() {

if (future != null) {

return;

}

future = gs.enqueue(new Callable<String>() {

@Override

public String call() throws Exception {

// Remove the kinetic control

proj.removeControl(ProjectileControl.class);



// Remove collision listener (this)

gs.getBulletAppState().getPhysicsSpace().removeCollisionListener(self);



// Remove projectile with its controls from ps

gs.getBulletAppState().getPhysicsSpace().removeAll(proj);



// Clear the projectile node

proj.getModelNode().detachAllChildren();

proj.detachAllChildren();



// Remove from projectiles node

proj.getParent().detachChild(proj);

return “ProjectileCollider(remove)”;

}

});

}[/java]



When not attaching to physics space this is the result, with a stable heap.

And no fps drop.



http://puu.sh/LREt.png

http://puu.sh/LREW.png



Has either of you run into this problem before, and found a cause of it/solution for it?

Or do either of you have a clue what might be happening?

Remove them not with removeAll() which only removes the first physics control of each spatial but do it with each by hand.

Yea found out, gah.



Fixed now thanks.