I want to know why FinalizerReference consume so much memory in my application

Viewed 1003

heap data

My application cant't run on android 4.x friendly,so I'm just analyzing my app's heap data,and I found that java.lang.FinalizerReference retained so much memory.Could any body can explain it?Any idea will be appreciated.

1 Answers

It doesn't, really.

I also encountered this problem, and I created a separate question and answer before finding yours. I think I actually got to the root of it.

tldr: Treating FinalizerReference like any other class when profiling (as Memory Profiler does), leads to repeated counting of the same memory when calculating Retained Size. So currently you can (almost always) regard the Retained Size of the FinalizerReference class reported by Memory Profiler as meaningless.

As Holger noted in the comments, only the 48 kB Shallow Size of the class (in your case) is usually important. However, the reported Retained Size of about 63 MB does not even include the referents' memory, only the recursively counted other instances of FinalizerReference. (unconvinced? read more)

But those referents are really important, especially any of them that are merely waiting to be finalize()'d before being garbage collected. So Memory Profiler should show them, as Holger assumed, because a large number of them would indicate a looming problem.

I view this as a bug in Android Studio's Memory Profiler, and have filed this issue.

Related