title: Avoid memory leaks on Android
body: <p>I just read <a href="http://www.curious-creature.org/2008/12/18/avoid-memory-leaks-on-android/">a blogpost by Romain Guy</a> on how to avoid memory leaks in Android.</p>
  
  <p>In the article he gives this example:</p>
  
  <pre><code>private static Drawable sBackground;
  
  @Override
  protected void onCreate(Bundle state) {
    super.onCreate(state);
  
    TextView label = new TextView(this);
    label.setText("Leaks are bad");
  
    if (sBackground == null) {
      sBackground = getDrawable(R.drawable.large_bitmap);
    }
    label.setBackgroundDrawable(sBackground);
  
    setContentView(label);
  }
  </code></pre>
  
  <p>Romain said:</p>
  
  <blockquote>
    <p>This example is one of the simplest cases of leaking the Context.</p>
  </blockquote>
  
  <p>My question is, how do you modify it correctly? </p>
  
  <p>Just like this?</p>
  
  <pre><code>TextView label = new TextView(Context.getApplicationContext());
  </code></pre>
  
  <p>I tested both ways and the results are the same. I can't locate the difference. And I think that <code>this</code> is more correct than the Application context. Because <code>this</code> is a reference to <code>Activity</code>, that is to say, the <code>TextView</code> belongs to that <code>Activity</code>.</p>
  
  <p>Could someone give me an explanation for this?</p>