title: How to avoid memory leaks in frame animation?
body: <p>I've created simple test app with one activity. The activity contains frame animation. The total size of images in frame animation(<code>riffle_forward_anim</code>) is about 1MB. Here is the code I use to load animation:</p>
  <pre class="lang-java prettyprint-override"><code>public class MainScreen extends Activity {
      /** Called when the activity is first created. */
  
      private ImageView imgForward;
      private ImageView imgBack;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          imgForward = (ImageView) findViewById(R.id.imgForward);
  
          imgForward.setBackgroundResource(R.anim.riffle_forward_anim);
  
      }
  
      @Override
      public void onPause(){
          super.onPause();
          AnimationDrawable anim = (AnimationDrawable) imgForward.getBackground();
  
  
  
          int count = anim.getNumberOfFrames();
          for(int i=0;i&lt;count;i++){
              anim.getFrame(i).setCallback(null);
          }
  
          imgForward.getBackground().setCallback(null);
  
          imgForward = null;
      }
  }
  </code></pre>
  <p>As you can see I try to release memory in <code>onPause()</code> method. Yes, I've read  <a href="http://developer.android.com/resources/articles/avoiding-memory-leaks.html" rel="nofollow noreferrer">http://developer.android.com/resources/articles/avoiding-memory-leaks.html</a></p>
  <p>Anyway crash occurs if I change portrait/landscape mode several times.
  I understand that I can handle orientation change and avoid crash but I need to release memory in my other app without orientation change. That is why I've created simple test app to understand how releasing memory works.
  Can anyone give me a hint on how to implement this?</p>
  <p>Thanks</p>