Alike question: https://hub.jmonkeyengine.org/t/memory-leak-using-multiple-parallel-physics-spaces-native-bullet/35743
Example Demo code: GitHub - qiunet/Jme3MemoryLeak: Jme3 Memory Leak demo
ENV: MACOS Big sur JDK 8
Run the example code above, The memory in monitor rise up continuious until process be kill by system!
I do not know is it a bug? Or incorrect use!
2 Likes
sgold
March 17, 2023, 5:28am
2
<groupId>org.jmonkeyengine</groupId>
<artifactId>jme3-bullet-native</artifactId>
<version>3.3.2-stable</version>
jme3-bullet is no longer maintained. Please switch to jme3-jbullet, or better yet, Minie .
3 Likes
Ali_RS
March 17, 2023, 5:53am
3
By the way, I am not sure if it is safe to destroy physics space from a different thread than it is created in.
server.start(JmeContext.Type.Headless);
AtomicInteger counter = new AtomicInteger();
int i = 0;
for (;;) {
Room room = new Room(server, i ++);
counter.incrementAndGet();
service.schedule(() -> {
counter.decrementAndGet();
room.destroy();
}, ThreadLocalRandom.current().nextInt(10, 50), TimeUnit.SECONDS);
System.out.println("Create total count: "+i+", Current alive count:" + counter.get());
Thread.sleep(ThreadLocalRandom.current().nextInt(200, 900));
}
}
@Override
public void simpleInitApp() {
this.setPauseOnLostFocus(false);
this.setDisplayStatView(false);
maybe you should use the app.enqueue(() -> room.destroy())
to make sure it is destroyed from the JME thread.
or else move the physicsSpace.destroy();
code from the stateDetached()
into the cleanup()
method of the Room
app state because cleanup is always executed from the JME thread.
1 Like
Thank you, Maybe it is a cause to leak too!
sgold
March 17, 2023, 7:08am
6
it work, thanks!
You’re welcome.
And by the way, welcome to the JMonkeyEngine forum!