0

I am using AnimationDrawable to play a PNG Sequence which works fine.. the problem is after adding this part the application went from using ~7MB of RAM to ~32MB..

I know we can't directly make call to release memory, but isn't there some way to minimise memory use after such Animation..

ColdFire
  • 6,764
  • 6
  • 35
  • 51
  • Can we assume that your using the following methodology for implementing the AnimationDrawable as describe here http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html – Emile Aug 26 '12 at 12:50
  • yes I am using this way..that's why I didn't use the `.recycle` method. On the other hand in the way I described worked perfectly... – ColdFire Aug 26 '12 at 13:03

3 Answers3

0

I think I found a solution. I fixed the issue by setting the background resource to the last drawable of the sequence, setting the AnimationDrawable to null and then calling the garbage collection

animationDrawable = null;
imageView.setBackgroundResource(R.drawable.last_png);
System.gc();
ColdFire
  • 6,764
  • 6
  • 35
  • 51
0

gc() only runs when it wants to and calling says you're open to having it done. But when you really need memory, calling it will do no good. Calling gc will NOT guarantee that memory is cleaned up and you'll have enough to run.

You need to drop the resources you're done using and load them as needed to keep your ram usage low.

Martin
  • 4,711
  • 4
  • 29
  • 37
  • yes I know about that.. but removing the line `System.gc()` doesn't change ram usage and when I keep it everything is done as expected..I have no explanation – ColdFire Aug 26 '12 at 10:48
0

Animation Drawable causing OutOfMemoryError on second run in Android

The answer to this question proposes a solution to freeing the bitmaps used in the animation drawable, calling .recycle() to free the bitmap. You would expect the AnimationDrawable to do this for you, which it may in fact do when you leave the activity, however this might work for you without having to rely on System.gc();

This seems to have been a common issue. The above link is the best answer so far.

Community
  • 1
  • 1
Emile
  • 11,451
  • 5
  • 50
  • 63