0

I'm writing a java applet with a reset button so that users can restart the app with a specified number of objects, and when the reset button is clicked, this method that I have defined gets called:

 public void reload(int new_number){
   init_num_objects =  new_number;
   this.destroy();
   this.init();
 }

This button technically does exactly what I want, it changes the value of a variable that init calls and restarts the applet:

public void init(){
  load_objects(init_num_objects);
}

The problem is that the more and more the user clicks the reset button, the slower the program (and consequently the user's computer) become. It's as if the applet is reloading each time without clearing memory space from the previous process. Is there a way to make the program just completely close and restart without slowing the client machine down?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
kjh
  • 3,407
  • 8
  • 42
  • 79
  • 1
    You've probably got some class that is keeping references to stuff even after you "reset". What does `load_objects()` do, anyway? – DGH Aug 03 '12 at 17:53
  • It displays an object of class Particle (I created the class) to the screen. It's not a native method, it's just a couple blocks of code I moved from the init method to make it easier to read. it calls add(object) on each object in an array – kjh Aug 03 '12 at 17:54
  • What's in the destroy method? Are you dereferecing all te cached values? It sounds like a memory leak & the GC s running not ones trying to free more memory – MadProgrammer Aug 03 '12 at 21:06

1 Answers1

2

How to reset an applet so that the information is not piled up each time?

// in the applet..
this.getAppletContext().showDocument( this.getDocumentBase() );

The JVM will call stop() & destroy() automatically, refresh the page, and call init() and start(). Alter the document base URL to include a parameter for the 'count'. Read the parameter using JS and write the new applet element accordingly.

I am not surprised things go wrong when the applet calls methods that are intended to be called automatically by the JVM.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433