(Slick2D) Image destroy necessary?

Quick question. In Slick2d, when I am done using an image, do I have to call it’s destroy method in order for it to be eligible for garbage collection?

destroy() removes the texture data from the gpu, has nothing to do with the garbage collection.
image = null would case that (you have to kill all references of course)

if you want to free VRam, you do destroy. When closing the Slick App, all is released anyway.

So, lets say that the Image is GC’d. Will the texture still sit there in VRAM?

Yup it will.

@davedes
You should override the finalize() method in Image (and all destroy-able classes) to call destroy().

I don’t think finalize() is the way to go for various reasons:

  • It may take a very long time after releasing the object before finalize() gets called.
  • It may never be called at all – therefore it’s not a good thing to rely on for VRAM cleanup.
  • IMO the control of releasing and reloading data into GPU should be in the hands of the user rather than the GC.
  • It may be called from the finalizer thread, which I presume would cause issues with the GL context.

Regarding the OP’s question, always destroy/release data (sounds, images) when you no longer need them. Simply setting them to null may make the object eligible for garbage collection, but it won’t necessarily unload the data from the GPU.