android – Memory leak caused by java.lang.ref.FinalizerReference-ThrowExceptions

Exception or error:

when launch com.android.gallery3d and press back key for about 2000 times i got exception of java.lang.OutOfMemoryError.
Dump heap of com.android.gallery3d which is in android 4.0.4.Use MAT to analyse and found java.lang.ref.FinalizerReference was nested called. What could cause this nested called?

android.app.ContextImpl @ 0x418f8c98
android.media.AudioManager @ 0x419495c8
android.media.AudioManager$1 @ 0x41949688
java.lang.ref.FinalizerReference @ 0x419496a8
java.lang.ref.FinalizerReference @ 0x419496e8
java.lang.ref.FinalizerReference @ 0x41949800
java.lang.ref.FinalizerReference @ 0x41949848
java.lang.ref.FinalizerReference @ 0x41949890
java.lang.ref.FinalizerReference @ 0x419498d8
java.lang.ref.FinalizerReference @ 0x41949920
java.lang.ref.FinalizerReference @ 0x419499b0
java.lang.ref.FinalizerReference @ 0x419499f8
java.lang.ref.FinalizerReference @ 0x41949a40
java.lang.ref.FinalizerReference @ 0x41949a88
java.lang.ref.FinalizerReference @ 0x41949ad0
java.lang.ref.FinalizerReference @ 0x4194a5a8
java.lang.ref.FinalizerReference @ 0x4194af48
java.lang.ref.FinalizerReference @ 0x4194b878
How to solve:

I had these symptoms in my application and it turned out to be related to a memory leak.
I used to register a callback from an activity to a singleton object. Destruction of the activity was pending on that of callback.

###

In my case I was creating a new (albeit small) object in the overridden onDraw method of my custom SurfaceView.

Leave a Reply

Your email address will not be published. Required fields are marked *