title: [Java]Interfaces and memory leaks
body: <p>I have doubt about interfaces and memory leaks, considering the block of code below, could it bring to a memory leak?
  If so what's the best solution or alternative?</p>
  
  <pre><code>public class MyClass {
      public interface MyClassListener{
           doStuff();
      }
  
      public doSomething(){}
  }
  
  public class OtherClass {
  
      private List&lt;MyClass&gt; list = new ArrayList&lt;MyClass&gt;();
      private boolean doingStuff = false;
  
      public void setListener(MyClassListener list) { //Sets the listener}
  
      public MyClass.MyClassListener listener = new MyClass.MyClassListener() {
          public void doStuff(){ doingStuff = true; }
      }
  
      public void addMyClass(MyClass obj) {
          obj.setListener(listener);
          list.add(obj);
      }
  
      public void doSomethingInMyClass(int index) {
          ....update some stuff....
          list.get(index).doSomething();
      }
  }
  </code></pre>
  
  <p>i know i could declare the variable <code>listener</code> as <code>static</code> so it wont hold a reference to <code>OtherClass</code> and assign that reference to a <code>WeakReference</code> but am i going to a memory leak anyway?
  Since the reference will hold a reference to an object containing a list which contains my object. It is like a chain.</p>
  
  <p><strong>Update</strong></p>
  
  <p>I updated my question, as you can see <code>MyClass</code> has a method called <code>doSomething()</code>, instead <code>OtherClass</code> has a method called <code>doSomethingInMyClass</code> which calls the <code>doSomething</code> method but updates some parameters.
  What i want is to avoid to use <code>doSomethingInMyClass</code> and get notified of the changes anyway.</p>