[SOLVED] PhysicsSpace create and destroy will trigger memory LEAK

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
            <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

By the way, I am not sure if it is safe to destroy physics space from a different thread than it is created in.

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

It it work, thanks!

2 Likes

Thank you, Maybe it is a cause to leak too!

it work, thanks!

You’re welcome.
And by the way, welcome to the JMonkeyEngine forum!