2

I am trying to analyze the memory usage of the Android app. I do that using

adb shell dumpsys meminfo <package name>

My app has only one Activity and I repeat the following steps probably a dozen of times:

  1. open the app;
  2. exit using the back button

After doing that a dozen of times dumpsys shows that around 1-2 instances of my Activities are still in memory. After I hit adb dumpsys for a couple of times the Activity count goes down to zero. Is this normal? If it is a leak I don't expect the Activity count to go down to zero. Does that mean GC claims the memory of the Activity objects slowly?

Onik
  • 19,396
  • 14
  • 68
  • 91
Bajji
  • 2,243
  • 2
  • 22
  • 35
  • Try analyzing your app's memory usage with LeakCanary https://github.com/square/leakcanary. You will be able to pinpoint the problem much easier. – Eric Bachhuber Jun 18 '16 at 00:00
  • @EricBachhuber Thank you. I did use Leak canary and got rid of the leaks. All I am left with now is only false positives, Leak Canary thinks that activity has leaked and later says that "GC was being lazy". So I think Leak canary wise I have no leaks. – Bajji Jun 18 '16 at 00:03

1 Answers1

2

Does that mean GC claims the memory of the activity objects slowly?

Finishing an Activity by pressing the back button does not mean its instance will be immediately killed and the memory GC-ed. The Activity's onDestroy() method is not a "finalizer". One can meet the case when by the time of starting a new Activity instance the "old" one is still sitting in memory (as a reference).

If it is a leak I don't expect the activity count to go down to zero.

If you see the app's process running it's not a leak as "the activity count goes down to zero".

After I hit adb dumpsys for a couple of times the activity count goes down to zero. Is this normal?

Yes, by the reasons described above.

Community
  • 1
  • 1
Onik
  • 19,396
  • 14
  • 68
  • 91