Memory exception with frame animation

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Memory exception with frame animation

Postby Zzokk » Mon Jan 25, 2010 3:35 pm

I've created simple test app with one activity. The activity contains frame animation. The total size of images in frame animation(riffle_forward_anim) is about 1MB. Here is the code I use to load animation:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class MainScreen extends Activity {
  2.  
  3. /** Called when the activity is first created. */
  4.  
  5.  
  6.  
  7. private ImageView imgForward; private ImageView imgBack;
  8.  
  9.  
  10.  
  11. @Override
  12.  
  13. public void onCreate(Bundle savedInstanceState) {
  14.  
  15.     super.onCreate(savedInstanceState);
  16.  
  17.     setContentView(R.layout.main);
  18.  
  19.  
  20.  
  21.     imgForward = (ImageView) findViewById(R.id.imgForward);
  22.  
  23.  
  24.  
  25.     imgForward.setBackgroundResource(R.anim.riffle_forward_anim);
  26.  
  27.  
  28.  
  29. }
  30.  
  31.  
  32.  
  33. @Override
  34.  
  35. public void onPause(){
  36.  
  37.  super.onPause();
  38.  
  39.  AnimationDrawable anim = (AnimationDrawable) imgForward.getBackground();
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  int count = anim.getNumberOfFrames();
  48.  
  49.  for(int i=0;i<count;i++){
  50.  
  51.   anim.getFrame(i).setCallback(null);
  52.  
  53.  }
  54.  
  55.  
  56.  
  57.  imgForward.getBackground().setCallback(null);
  58.  
  59.  
  60.  
  61.  imgForward = null;
  62.  
  63. }
  64.  
  65.  
  66.  
  67. }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


As you can see I try to release memory in onPause() method. Yes, I've read http://developer.android.com/resources/ ... leaks.html

Anyway crash occurs if I change protrait/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 realisng memory works. Can anyone give me a hint on how to implement this?

Thanks
Zzokk
Freshman
Freshman
 
Posts: 2
Joined: Mon Jan 25, 2010 3:30 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 3 guests