M-Wajeeh
M-Wajeeh

Reputation: 17284

Possible memory leak Android

I ran this command adb shell dumpsys meminfo <package_name> and got

 Objects
               Views:       74         ViewRootImpl:        1
         AppContexts:        3           Activities:        1
              Assets:        4        AssetManagers:        4
       Local Binders:       11        Proxy Binders:       20
    Death Recipients:        0
     OpenSSL Sockets:        2

 SQL
         MEMORY_USED:        0   
  PAGECACHE_OVERFLOW:        0          MALLOC_SIZE:        0

after pressing back button and launching app again and just repeating this process several times gives:

 Objects
               Views:     1408         ViewRootImpl:        8
         AppContexts:       14           Activities:       12
              Assets:        5        AssetManagers:        5
       Local Binders:       13        Proxy Binders:       32
    Death Recipients:        0
     OpenSSL Sockets:        1

 SQL
         MEMORY_USED:        0
  PAGECACHE_OVERFLOW:        0          MALLOC_SIZE:        0

Note the Activities and AppContexts count they just keep increasing by just launching the app again and again. Does this mean I have a memory leak?

I read this document https://developer.android.com/tools/debugging/debugging-memory.html#ViewingAllocations which says:

AppContexts and Activities The number of app Context and Activity objects that currently live in your process. This can be useful to quickly identify leaked Activity objects that can’t be garbage collected due to static references on them, which is common. These objects often have a lot of other allocations associated with them and so are a good way to track large memory leaks.

Upvotes: 1

Views: 673

Answers (2)

Bartosz Bilicki
Bartosz Bilicki

Reputation: 13235

Most common cause of memory leak in Android is keeping instance of

  • Activity
  • Context
  • Bitmap/Drawable
  • Resources

in some containers that live longer than Activity itself. Those containers may be

  • callbacks
  • static variables

Watch https://www.youtube.com/watch?v=_CruQY55HOk for excelent analisys how to find memory leaks using Memory Analyser Tool and heap dumps.

Upvotes: 1

Felipe Silveira
Felipe Silveira

Reputation: 533

It seems to be a memory leak. To make sure it is, you can force run garbage collector after each iteration test (you can do it using DDMS). Doing this, you will have sure it is a memory leak.

After that, you can use MAT (Memory Analyser Tool - http://www.eclipse.org/mat/) to identify which references are causing the leak.

Good luck!

Upvotes: 0

Related Questions