title: JPG as background in Activity produces memory leak
body: <p>my little App always crashed after the 5th or 6th screen-rotation. Two main layouts are defined, one for landscape one for portrait. After spending the whole day looking for the memory leak I found the problem: I had a JPG defined as background for the Main-Activity. After changing the JPG to a PNG the memory problem was solved.</p>
  
  <p>The background was defined as drawable and was defined in main.xml.</p>
  
  <p>The problem did not come when I tested the App under 2.2 (emulator) but with 2.3.1 (also emulator) the app crashed.</p>
  
  <p>Can someone reproduce this problem?</p>
  
  <hr>
  
  <p>Now I reduced my app to the following code:</p>
  
  <pre><code>package at.memtest;
  
  import android.app.Activity;
  import android.graphics.drawable.BitmapDrawable;
  import android.os.Bundle;
  import android.widget.LinearLayout;
  
  public class MemTestActivity extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(final Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  }
  
  @Override
  protected void onDestroy() {
      recycleImages();
      super.onDestroy();
  
  }
  
  @Override
  protected void onPause() {
      recycleImages();
      super.onPause();
  }
  
  
  private void recycleImages() {
      final LinearLayout theView = (LinearLayout) findViewById(R.id.main_layout);
      if (theView != null) {
          final BitmapDrawable background = (BitmapDrawable) theView.getBackground();
          if (background != null) {
              background.getBitmap().recycle();
          }
      }
  }
  }
  </code></pre>
  
  <p>Now the memory stays constant...
  Can you imaging that this is necessary to avoid memory leaks?
  As I said above - the image I use as a background is a PNG with about 220K.</p>