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?
I think that is a bit dependenent upon the "glue" or binding, how it chooses to implement ownership.
In general, I would expect bindings to stick to OpenGL semantics, meaning the JVM is not involved in garbage-collecting the data held by the OpenGL library.
In many cases, e.g. texture uploads, I think this is the only way it can work.
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 glDelete
functions.
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".