title: Warning: This AsyncTask class should be static or leaks might occur
body: <p>I am getting a warning in my code that states:</p>
  
  <blockquote>
    <p>This AsyncTask class should be static or leaks might occur (anonymous android.os.AsyncTask)</p>
  </blockquote>
  
  <p>The complete warning is:</p>
  
  <blockquote>
    <p>This AsyncTask class should be static or leaks might occur (anonymous android.os.AsyncTask) 
    A static field will leak contexts.  Non-static inner classes have an implicit reference to their outer class. If that outer class is for example a Fragment or Activity, then this reference means that the long-running handler/loader/task will hold a reference to the activity which prevents it from getting garbage collected.  Similarly, direct field references to activities and fragments from these longer running instances can cause leaks.  ViewModel classes should never point to Views or non-application Contexts.</p>
  </blockquote>
  
  <p>This is my code:</p>
  
  <pre><code> new AsyncTask&lt;Void,Void,Void&gt;(){
  
          @Override
          protected Void doInBackground(Void... params) {
              runOnUiThread(new Runnable() {
  
                  @Override
                  public void run() {
                      mAdapter.notifyDataSetChanged();
                  }
              });
  
              return null;
          }
      }.execute();
  </code></pre>
  
  <p>How do I correct this?</p>