LibGDX: Memory management concerning Textures

Hi,
I would like to know a bit more about memory management, and specifically concerning textures.
I’ve been looking around for some stuff to read online but couldn’t quite find what I was looking for.
Maybe you guys have a good resource/link for me?

Something like this code for example:


public void setPuzzleImage() {
     if (puzzleImage != null){
			puzzleImage.dispose();
		}
	puzzleImage = new Texture(paintingsHashMap.get(SELECTEDPAINTING).getFilepath_painting());
}

From my puzzlegame…Whenever I start a new puzzle I check if puzzleImage is already pointing to a Texture object, and if so, disposes that Texture before creating a new object.
I have no idea if this is even usefull at all… If the memory that the previous texture-object held is already automatically freed up when it’s pointer/variable (puzzleImage) is pointing to a new object or not, etc.

Any suggestion ?

Since it’s a libGDX texture, it might very well involve memory on the GPU, which is special and thus necessitates the dispose() method. Any other normal memory the object consumes (the Java object instance) is just like any other Java object and the memory is freed automatically by the garbage collector at some point when there are no references to the object (it is unreachable by the program), such as if puzzleImage is the only reference and you pointed it at something else like your code does.

Garbage collection isn’t magic, in fact the core concept is pretty simple: http://journal.stuffwithstuff.com/2013/12/08/babys-first-garbage-collector/

From my understanding of LibGDX anything that has a dispose method will not be garbage collected automatically and it is necessary to use the dispose method otherwise you will have memory leaks.