Native memory and SaferAlloc¶
A game uses memory to hold its objects, textures, models and other data. Some of that data is stored in native memory: memory outside the Java heap that the engine uses to communicate with graphics, audio and other native code.
SaferAlloc manages native memory allocations for the engine. It uses a hardened allocator to improve memory safety and tracks native memory usage to help manage memory pressure. When native memory use grows, the engine can respond to that pressure and help reclaim memory that is no longer needed.
Add the module to your project and the engine automatically starts using SaferAlloc for its native memory allocations. The LWJGL backend uses it as well.
Continue using BufferUtils as usual: its native buffers automatically benefit from SaferAlloc without changes to your game code.
Add SaferAlloc¶
When creating a project with the Initializer, choose the hardened native allocator. The Initializer adds the jme3-saferallocator module to your project.
To add it to an existing Gradle project, use the same jMonkeyEngine version as your other engine modules:
dependencies {
implementation 'org.jmonkeyengine:jme3-saferallocator:<jme-version>'
}
Replace <jme-version> with your project's engine version.