Quote from: bonenaut7 on May 13, 2024, 02:11:24That's interesting, i was using MemoryStack only in try-with-resources blocks, but in example i provided in #1 post it looks like that's... unnecessary? There is callback when vertex buffer is built, BGFXMemory is no more required to stay and memory could be freed(and it happens exactly when at least a frame with some delay passed), is this callback bad in some way?Allocating native memory (especially in a game loop) is slow (regardless of language). The advantage with the above MemoryStack method is that you just allocate a chunk of memory at initialisation and then reuse it continuously in the game loop.
Quote from: spasi on May 12, 2024, 09:39:10The Java-side buffer object that wraps a native pointer is reclaimed as usual by the GC, when there are no longer any references pointing to it.Oh, got it, thanks!
Quote from: kappa on May 12, 2024, 05:47:35One potential solution for frame data which changes every frame (e.g. immediate mode 2d graphics made up of many small allocations) is to use LWJGL's MemoryStack, just push all your data in there and pop (release) it after 2 frames. e.g. Use 3 MemoryStack's (one for current frame data and two holding data for the previous two frames) and just cycle through the MemoryStack's.
Configuration.DEBUG_MEMORY_ALLOCATOR.set(true);
(or -Dorg.lwjgl.util.DebugAllocator=true
) which enables tracking and memory leak reporting for any native allocation that goes through MemoryUtil's memory allocator (see Configuration.MEMORY_ALLOCATOR
). As I mentioned, this tracking may introduce a lot of overhead, depending on the application (a stacktrace is captured on every allocation, which can optionally be disabled with Configuration.DEBUG_MEMORY_ALLOCATOR_FAST
). But it can accurately report memory leaks and you can also use it to print memory usage statistics at runtime.bgfx_make_ref_release
that i can use to get BGFXMemory
and i have problem with this. When i'm using this method, memory reference should be destroyed after some time (at least a single BGFX.bgfx_frame
call, and a few milliseconds to process commands), so after waiting, native(i guess) side calls BGFXReleaseFunctionCallbackI#invoke
method, where i should by logic use something like MemoryUtil.nmemFree(_ptr)
(took this from examples) to free this reference, which points on the ByteBuffer
and it's Buffer#address
that i used to create this reference. But there's a thing, i don't know is it freed or not, because MemoryUtil#nmemFree
nor MemoryUtil#memFree
are setting anything to a buffer (for example Buffer#address
field to 0).BGFXMemory
is freed or not? I'm noticed that even after buffer's memory address being freed, i still can use that buffer and this whole thing kinda scares meQuote from: spasi on May 10, 2024, 12:15:10The log shows that the JVM itself is trying to allocate some memory and fails. Are you maybe running too many programs and the system as a whole runs OOM?Not really many programs, just a few like intellij and a web browser. But yes, the whole system get frozen. It ate up all mermory.
In any case, this doesn't look like an issue with LWJGL.