title: why use WeakReference on android Listeners?
body: <p>I am working on a large code base, and see in many places this type of code:</p>
  
  <pre><code>public static class RequestCustomData implements View.OnClickListener {
      WeakReference&lt;MainActivity&gt; mainActivity;
  
      public RequestCustomData(MainActivity activity) {
          mainActivity = new WeakReference&lt;&gt;(activity);
      }
  
      @Override
      public void onClick(View view) {
          MainActivity activity = mainActivity.get();
          activity.requestCustomData(true, null);
      }
  }
  </code></pre>
  
  <p>I am a bit confused why this is used is so many places? I took a look at this document but it did not clarify well why this type of code is so heavily used on the app I am working on it</p>
  
  <p><a href="https://community.oracle.com/blogs/enicholas/2006/05/04/understanding-weak-references" rel="noreferrer">https://community.oracle.com/blogs/enicholas/2006/05/04/understanding-weak-references</a></p>
  
  <p>Anyone can explain me if this is a common pattern? If so, why?</p>