title: Free memory from AnimationDrawable
body: <p>I'm using animationdrawables in many activities of my app. This is the code to inicializate them:</p>
  
  <pre><code> public void prepareVideo (int resourceBall, String animation, int width, int height ){
  
      imgBall = (ImageView)findViewById(resourceBall);
      imgBall.setVisibility(ImageView.VISIBLE);
      String resourceNameAnimation = animation;
      int id_res = getResources().getIdentifier(resourceNameAnimation, "drawable", getPackageName());
      imgBall.setBackgroundResource(id_res);
          LayoutParams latoutFrame = imgBall.getLayoutParams();
      latoutFrame.width = width;
      latoutFrame.height = height;
      imgBall.setLayoutParams(latoutFrame); 
      frame = (AnimationDrawable) imgBall.getBackground();
  
  
  }
  </code></pre>
  
  <p>Then i call:
      imgBall.post(new StartAnimation());</p>
  
  <p>that call a  runnable:</p>
  
  <pre><code>class StartAnimation implements Runnable {
  
      public void run() {
  
  frame.start();
  
      }
  
  }
  </code></pre>
  
  <p>The problem is i use many animations that are the uses the same xml (frame by frame). I have to call this method in many activities with the same animation. Finally i get a outofmemoryerror. I'm trying to free memory between screens:</p>
  
  <pre><code>for (int i = 0; i &lt; frame.getNumberOfFrames(); ++i){
       Drawable frame_rescue = frame.getFrame(i);
       if (frame_rescue instanceof BitmapDrawable) {
           ((BitmapDrawable)frame_rescue).getBitmap().recycle();
       }
       frame_rescue.setCallback(null);
  </code></pre>
  
  <p>The problem is that when i try to use a resourde again y get other error:
  "Trying to use recycled bitmap"</p>
  
  <p>Anyone know other way of free memory?</p>