LWJGL Forum

Please login or register.

Login with username, password and session length

Author Topic: Native Buffer Management  (Read 110 times)

Vektor

  • Newbie
  • *
  • Offline Offline
  • Posts: 2
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().
Logged

Cornix

  • Nerdus Imperius
  • *****
  • Offline Offline
  • Posts: 471
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.
Logged

Vektor

  • Newbie
  • *
  • Offline Offline
  • Posts: 2
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.
Logged