Memory Leak of java.lang.ref.FinalizerReference on Android

Recently I’m working on a memory leak issue of Android. By using “Dump HPROF file” tool in DDMS, I found some objects are retained by java.lang.ref.FinalizerReference. After some investgation, I found the reason.

We have an object A, and A have a reference to a activty B. A will be recreated during refresh, while B won’t. And we have some code like this.

1
A.B.runUiThread();

Even A is no longer needed, the system will still hold the reference to it.

The solution is simple.

1
2
Activity lB = A.B;
lB.runUiThread();

发表评论