Restart an Application

i tried to restart my application with the following code:


@SuppressWarnings("static-access")
   public void rebuild() {
      cleanup();
      rootNode.detachAllChildren();
      rootNode.clearControllers();
      display.close();
      CP_TestDriver.main(null);
      System.exit(0);
   }



it works but all the texture and menu things are really crazy drawn. i think i should flush all the render states and delete all the objects. but how can i do that? because i can't use system.exit().