When using openGL in Java (in bindings like jogl), do you have to worry about memory management? Does the JVM do garbage collection with the created openGL objects? If so, what’s the best way to approach cleanup?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In the lower-level bindings for OpenGL like JOGL (but probably not so much for libraries like Java3D), you do have to manage resources like textures and buffers yourself by calling the
glDeletefunctions.OpenGL does things like move textures to and from video memory when necessary for rendering. There isn’t a practical way for the Java garbage collector to collect these resources because they aren’t represented as Java objects once they’re handed off to OpenGL. Yes, this means that you have to keep around lists of resources in use by OpenGL.
The good news is that you can probably load more resources into OpenGL than you might think, since it will take care of swapping them to the video memory when needed and back to main memory when not. The bad news is that there’s still a practical limit on the size and number of resources (e.g. textures) that can be used to render a frame without this ‘thrashing’.