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

My dispose looks something like this

public void dispose() {

and I use


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?

  • \$\begingroup\$ Can you show the exception thrown when it crashes? \$\endgroup\$
    – bornander
    Dec 7, 2015 at 20:39
  • 1
    \$\begingroup\$ The crash is probably because you used the function to call itself, with infinite recursion. You're probably looking for super.dispose() \$\endgroup\$ Dec 7, 2015 at 20:58

1 Answer 1


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 :)

Hope this helps! ~ Ammar Tarajia


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .