title: Clear Singleton instance in Java
body: <p>I have a Singleton class to save the state of an application's module.
  This class simply have a lot of class variables with setters and getters :</p>
  
  <pre><code>public class ModuleState{
  
  private static ModuleState instance;
  
  private A a;
  private B b;
  private C c;
  ..
  ..
  ..
  ..
  
  private ModuleState (){}
  
  public ModuleState getInstance(){
      if(instance==null)
          instance=new ModuleState();
  
      return instance;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>At a precise moment of the application lifecycle, i have the need to CLEAR the module's state. What i do now is to reset ALL the variables in ModuleState by a clearAll() method like this:</p>
  
  <pre><code>public void clearAll(){
      a=null;
      b=null;
      c=null;
  
      ..
      ..
  }
  </code></pre>
  
  <p>My question is the following : there is a cleaner method to do this reset? Possibly clearing the singleton instance itself, without resetting every class variable?</p>
  
  <p>The problem with this approach is that i may have the need to add a new class variable to the ModuleState. In this case i must remember to add a line in the clearAll() method to reset the new variable.</p>