Hello Guest

Native Buffer Management

  • 2 Replies
Native Buffer Management
« on: November 04, 2017, 03:58:56 »
Hey Guys,

This is my first post but I have been working with LWJGL3 for a while now. Now that I've finally got around to making an account here I hope to be more active on these forums. Recently, I have been thinking a lot about various techniques for managing native buffers (created via glGenBuffers and set with glBufferData) in my game engine. I have been able to successfully manage the native buffer memory, but I do have a few questions that I haven't been able to easily find answers for anywhere else.

1.) What happens to the memory occupied by natively allocated buffers when the application or JVM terminates unexpectedly (like when a NullPointerException is thrown)? Are they automatically freed when the JVM exits or does the memory get "stuck" in the GPU until the next system restart?

2.) This question is somewhat related to my previous question. My engine is designed to automatically free any active buffers and vertex arrays via glDeleteBuffers() and glDeleteVertexArrays() when the application is stopped. Is it necessary to do this? Is there an easier way to free up ALL natively allocated buffers other than calling glDeleteBuffers() and glDeleteVertexArrays() on each one?

Some additional info: I am using memAlloc() to create the buffers. I am also freeing them using memFree() directly after passing the buffer data into glBufferData().
« Last Edit: November 04, 2017, 04:01:15 by Vektor »


Offline Cornix

  • *****
  • 480
Re: Native Buffer Management
« Reply #1 on: November 04, 2017, 08:05:45 »
When the application exits the OpenGL context is destroyed and with it all resources are automatically freed. There is no need to worry about memory leaks after the application has terminated.

Re: Native Buffer Management
« Reply #2 on: November 04, 2017, 15:18:05 »
Thank you for the prompt response. That is exactly what I needed to know.