title: Activity's member scope and Asynctask
body: <p>I initialize a member variable in my Activity class</p>
  
  <pre><code>private String test = new String("A");
  </code></pre>
  
  <p>then I use it to write to Log in a long time consuming loop in <code>doInBackground()</code> method of an anonymous AsyncTask launched from the Activity</p>
  
  <pre><code>new AsyncTask&lt;Void, Void, Void&gt;() {
     @Override
     protected void onPreExecute() {
     }
  
     @Override
     protected void onPostExecute(Void result) {
     }
  
     @Override
     protected Void doInBackground(Void... params) {
  
       for (int j = 10; j &gt;= 0; j--) {
          try {
              Thread.sleep(5000);
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
          Log.i("DOINBACKGROUND ", test);
       }
  
  }.execute(); 
  </code></pre>
  
  <p><strong>QUESTION</strong>:
  When I leave Activity while <code>Asynctask</code> is still executing, and <strong>after Activity's <code>onDestroy()</code> is executed</strong>, I see in the Log that the member variable is still alive and not destroyed. Can someone explain to me how is it possible?</p>
  
  <p><strong><em>BOUNTY QUESTION</em></strong>: 
  the member variable is still alive because, even after <code>onDestroy()</code>, it isnt yet garbaged due to gc criteria and gc priority. This is ok.</p>
  
  <p>But my doubt is if</p>
  
  <ul>
  <li>the 'test' member variable (and the activity's context) will not garbaged until the referencing asynctask ended its stuff, thus asynctask can complete its <code>doInBackground()</code> always and surely without crashing (although with a temporary memory consumption)</li>
  </ul>
  
  <p>or instead</p>
  
  <ul>
  <li>the 'test' member variable will be garbaged sooner or later regardless asynctask is running, maybe resulting in an asysnctask's crash</li>
  </ul>