I started a brand new sample project for this experiment. The app has one activity.
At this point I run the application and dump the java heap. The results are shown below:
Great! Everything looks correct. The "Total Count" and "Heap Count" are at 1. Exactly what I expected.
Let's rotate my device 3 times. At this point I'm still expecting to see only 1 MainActivity, but I understand that 4 have been created. Let's take a look.
Hmm... That's weird. It is showing 4. How could that be? Maybe the activities are still there. Unreferenced... but they haven't been GC'd yet. Let's force a GC and do another heap dump.
Strange. It's still at 4. This is where I'm lost. It sounds like either Total Count or Heap Count should be at 1. Is it just keeping every reference of MainActivity ever? Is that a leak? Is the viewer just wrong?
Total Count (according to the docs) is "Total number of instances outstanding."
Maybe Heap Count? "Number of instances in the selected heap." Well that sounds like more of what I want. I want the number of instances (real instances) with gc roots.
Does anyone have any idea why this is happening?