Statics are just the first thing to check.

On Dec 11, 5:32 am, Mark Hansen <stonedon...@gmail.com> wrote:
> So I did get the crashes to stop, and I have a idea of why it works...
> anyways.. I updated the onWindowFocusChange set the backGroundDrawable
> to null when the app loses focus.  I also do this on the onDestroy()
> and onPause() methods as well.
>
> My guess is that the app goes into pause mode and when restarted since
> I was reattaching the same animation to the ImageView it was causing a
> leak.
>
> Note this ImageView and Animation were not static variables they were
> loaded only on the onWindowFocusChange event.  I made the assumption
> since I was not letting my ImageView and Animation be created as
> static variables I wouldn't leak the Context, but apparently the
> recreation of the animation attachment to the ImageView was for some
> reason, this I'm not 100% sure on, but it seems to be the case.
>
> On Dec 10, 7:53 pm, Romain Guy <romain...@android.com> wrote:
>
> > DDMS has a feature to dump the Java heap. You can then analyze is
> > using tools like hat, MAT, JProfiler, etc.
>
> > On Thu, Dec 10, 2009 at 4:17 PM, Matt Kanninen <mathias...@gmail.com> wrote:
> > > Got any advice on tools to use to debug the most likely situation
> > > you've described?  I'm at the point where I've ruled out static
> > > variables.
>
> > > I'm working on code that started with Android 1.0, and has had a
> > > series of developers since.  Good code analysis tools could help
> > > immensely.  It beats re writing every class.
>
> > > On Dec 10, 3:47 pm, Romain Guy <romain...@android.com> wrote:
> > >> If there's an OutOfMemoryError, it's most likely that the app is using
> > >> too much memory and/or leaking. Filing a bug won't help.
>
> > >> On Thu, Dec 10, 2009 at 3:43 PM, Matt Kanninen <mathias...@gmail.com> 
> > >> wrote:
> > >> > Best of luck.  I recommend you create a very small test application to
> > >> > reproduce the bug, and submit it to b.android.com.
>
> > >> > On Dec 10, 12:52 pm, Mark Hansen <stonedon...@gmail.com> wrote:
> > >> >> So I want to start an animation when my application starts that always
> > >> >> visible in the application.  So reading about the AnimationDrawable it
> > >> >> was stated to use onWindowFocusChanged instead of onCreate() to ensure
> > >> >> that animation would start properly in the UI thread.
>
> > >> >>         @Override
> > >> >>         public void onWindowFocusChanged(boolean hasFocus) {
> > >> >>                 super.onWindowFocusChanged(hasFocus);
>
> > >> >>                 AnimationDrawable cam;
> > >> >>                 ImageView iv = 
> > >> >> (ImageView)findViewById(R.id.ImageViewFuzzAnimation);
> > >> >>                 iv.setBackgroundResource(R.anim.fuzz_animation);
> > >> >>                 cam = (AnimationDrawable)iv.getBackground();
> > >> >>                 cam.start();
>
> > >> >>         }
>
> > >> >> This works fine, but if I leave my application and come back I get a
> > >> >> out of memory error, below is the log..
>
> > >> >> Can anyone help me out on what I may be doing wrong here?
>
> > >> >> 12-10 15:52:14.365: ERROR/dalvikvm-heap(3102): 805600-byte external
> > >> >> allocation too large for this process.
> > >> >> 12-10 15:52:14.373: ERROR/(3102): VM won't let us allocate 805600
> > >> >> bytes
> > >> >> 12-10 15:52:14.373: DEBUG/skia(3102): --- decoder->decode returned
> > >> >> false
> > >> >> 12-10 15:52:16.490: DEBUG/dalvikvm(1570): GC freed 797 objects / 43592
> > >> >> bytes in 94ms
> > >> >> 12-10 15:52:20.147: DEBUG/AndroidRuntime(3102): Shutting down VM
>
> > >> >> 12-10 15:52:20.147: ERROR/AndroidRuntime(3102): Uncaught handler:
> > >> >> thread main exiting due to uncaught exception
> > >> >> 12-10 15:52:20.232: ERROR/AndroidRuntime(3102):
> > >> >> java.lang.OutOfMemoryError: bitmap size exceeds VM budget
> > >> >> 12-10 15:52:20.232: ERROR/AndroidRuntime(3102):     at
> > >> >> android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
> > >> >> 12-10 15:52:20.232: ERROR/AndroidRuntime(3102):     at
> > >> >> android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:447)
> > >> >> 12-10 15:52:20.232: ERROR/AndroidRuntime(3102):     at
> > >> >> android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:
> > >> >> 323)
> > >> >> 12-10 15:52:20.232: ERROR/AndroidRuntime(3102):     at
> > >> >> android.graphics.drawable.Drawable.createFromResourceStream
> > >> >> (Drawable.java:697)
> > >> >> 12-10 15:52:20.232: ERROR/AndroidRuntime(3102):     at
> > >> >> android.content.res.Resources.loadDrawable(Resources.java:1705)
> > >> >> 12-10 15:52:20.232: ERROR/AndroidRuntime(3102):     at
> > >> >> android.content.res.Resources.getDrawable(Resources.java:580)
> > >> >> 12-10 15:52:20.232: ERROR/AndroidRuntime(3102):     at
> > >> >> android.graphics.drawable.AnimationDrawable.inflate
> > >> >> (AnimationDrawable.java:265)
> > >> >> 12-10 15:52:20.232: ERROR/AndroidRuntime(3102):     at
> > >> >> android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:
> > >> >> 788)
> > >> >> 12-10 15:52:20.232: ERROR/AndroidRuntime(3102):     at
> > >> >> android.graphics.drawable.Drawable.createFromXml(Drawable.java:729)
> > >> >> 12-10 15:52:20.232: ERROR/AndroidRuntime(3102):     at
> > >> >> android.content.res.Resources.loadDrawable(Resources.java:1690)
> > >> >> 12-10 15:52:20.232: ERROR/AndroidRuntime(3102):     at
> > >> >> android.content.res.Resources.getDrawable(Resources.java:580)
> > >> >> 12-10 15:52:20.232: ERROR/AndroidRuntime(3102):     at
> > >> >> android.view.View.setBackgroundResource(View.java:7187)
> > >> >> 12-10 15:52:20.232: ERROR/AndroidRuntime(3102):     at
> > >> >> com.stonedonkey.santatracker.ActivityGUI.onWindowFocusChanged
> > >> >> (ActivityGUI.java:170)
> > >> >> 12-10 15:52:20.232: ERROR/AndroidRuntime(3102):     at
> > >> >> com.android.internal.policy.impl.PhoneWindow
> > >> >> $DecorView.onWindowFocusChanged(PhoneWindow.java:1969)
> > >> >> 12-10 15:52:20.232: ERROR/AndroidRuntime(3102):     at
> > >> >> android.view.View.dispatchWindowFocusChanged(View.java:3731)
> > >> >> 12-10 15:52:20.232: ERROR/AndroidRuntime(3102):     at
> > >> >> android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:656)
> > >> >> 12-10 15:52:20.232: ERROR/AndroidRuntime(3102):     at
> > >> >> android.view.ViewRoot.handleMessage(ViewRoot.java:1819)
> > >> >> 12-10 15:52:20.232: ERROR/AndroidRuntime(3102):     at
> > >> >> android.os.Handler.dispatchMessage(Handler.java:99)
> > >> >> 12-10 15:52:20.232: ERROR/AndroidRuntime(3102):     at
> > >> >> android.os.Looper.loop(Looper.java:123)
> > >> >> 12-10 15:52:20.232: ERROR/AndroidRuntime(3102):     at
> > >> >> android.app.ActivityThread.main(ActivityThread.java:4338)
> > >> >> 12-10 15:52:20.232: ERROR/AndroidRuntime(3102):     at
> > >> >> java.lang.reflect.Method.invokeNative(Native Method)
> > >> >> 12-10 15:52:20.232: ERROR/AndroidRuntime(3102):     at
> > >> >> java.lang.reflect.Method.invoke(Method.java:521)
> > >> >> 12-10 15:52:20.232: ERROR/AndroidRuntime(3102):     at
> > >> >> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
> > >> >> (ZygoteInit.java:860)
> > >> >> 12-10 15:52:20.232: ERROR/AndroidRuntime(3102):     at
> > >> >> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
> > >> >> 12-10 15:52:20.232: ERROR/AndroidRuntime(3102):     at
> > >> >> dalvik.system.NativeStart.main(Native Method)
>
> > >> > --
> > >> > You received this message because you are subscribed to the Google
> > >> > Groups "Android Developers" group.
> > >> > To post to this group, send email to 
> > >> > android-developers@googlegroups.com
> > >> > To unsubscribe from this group, send email to
> > >> > android-developers+unsubscr...@googlegroups.com
> > >> > For more options, visit this group at
> > >> >http://groups.google.com/group/android-developers?hl=en
>
> > >> --
> > >> Romain Guy
> > >> Android framework engineer
> > >> romain...@android.com
>
> > >> Note: please don't send private questions to me, as I don't have time
> > >> to provide private support.  All such questions should be posted on
> > >> public forums, where I and others can see and answer them
>
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Android Developers" group.
> > > To post to this group, send email to android-developers@googlegroups.com
> > > To unsubscribe from this group, send email to
> > > android-developers+unsubscr...@googlegroups.com
> > > For more options, visit this group at
> > >http://groups.google.com/group/android-developers?hl=en
>
> > --
> > Romain Guy
> > Android framework engineer
> > romain...@android.com
>
> > Note: please don't send private questions to me, as I don't have time
> > to provide private support.  All such questions should be posted on
> > public forums, where I and others can see and answer them
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to