# Libgdx crash on dispose()?

Whenever I try to manually call the dispose method in one of my screen my game just crashes.

My dispose looks something like this

@Override
public void dispose() {
battletheme.dispose();
renderer.dispose();
bg.dispose();
enemy.dispose();
dialouge.dispose();
GameTools.fontText.dispose();
}


and I use

this.dispose();


When I switch to another screen, otherwise my memory begins to pile up. Is there any reason for this?

EDIT: My spritebatch called "renderer" seems to crash on dispose, any reason?

• Can you show the exception thrown when it crashes? – bornander Dec 7 '15 at 20:39
• The crash is probably because you used the function to call itself, with infinite recursion. You're probably looking for super.dispose() – Draco18s no longer trusts SE Dec 7 '15 at 20:58

The dispose() function is made to be called at the end of the program's life cycle. You calling renderer.dispose() is manually garbage-collecting the renderer and this most likely works by setting it to null which will, in turn, cause the JVM to respond by destroying the object. You are probably trying to re-access the renderer object after it's destruction and failing by causing a NullPointerException which is produced when a variable contains a null value due to the fact that you can't use null to do anything as null means nothing :)