Gaca
Gaca

Reputation: 21

Android app memory issue

I'm making application for watching movies which shows images of categories and movies in grid, list and horizontal scroll view. App has several activities and in every one of them are shown images. Proglem is when user changes activities going only forward, in one point app crashes with OutOfMemory exception.

Using Heap and MAT tools i found that bitmap uses enormous memory of the heap in every activity. On same phones, like Samsung Galaxy S4 and Alcatel OneTouch Idol with full HD display, app crashes in just 2-3 activities. That is crazy :)

So, my question is, how can i overcome this problem with memory? I know that this is ordinary Android problem but there must be something that I can do to fix this.

Every image is optimazed for its place ( image dimensions are precisely measured before attached to image view). Cheers.

Upvotes: 2

Views: 393

Answers (1)

Imposter
Imposter

Reputation: 2686

Do some profiling .

You didn't provide any code or logs .So ,will tell you basic approach which i follow .

start your first activity . Continously run adb shell dumpsys "PID" or "PackageName" .

Get info while you reproduce activity . execute adb shell " while true ; do dumpsys meminfo 22188 ; done ; " > dumpsysOfsmthn.txt

* MEMINFO in pid 22188 [com.sec.android.smthn] **

                   Pss  Private  Private  Swapped     Heap     Heap     Heap

                 Total    Dirty    Clean    Dirty     Size    Alloc     Free

                ------   ------   ------   ------   ------   ------   ------

  Native Heap       44       44        0        0    11132    10455      184

  Dalvik Heap    19189    18804        0        0    25660    19221     6439

 Dalvik Other     3891     3828        0        0                           

        Stack      200      200        0        0                           

       Ashmem        2        0        0        0                           

    Other dev     8168     7844        4        0                           

     .so mmap     1990     1032      508        0                           

    .jar mmap        5        0        4        0                           

    .apk mmap      315        0      124        0                           

    .ttf mmap       21        0        4        0                           

    .dex mmap     6553      248     5584        0                           

   Other mmap       90        4       20        0                           

      Unknown     5743     5740        0        0                           

        TOTAL    46211    37744     6248        0    36792    29676     6623



 Objects

               Views:       39         ViewRootImpl:        1

         AppContexts:        4           Activities:        1

              Assets:        3        AssetManagers:        3

       Local Binders:       78        Proxy Binders:       42

    Death Recipients:        2

     OpenSSL Sockets:        0



 SQL

         MEMORY_USED:      286

  PAGECACHE_OVERFLOW:       53          MALLOC_SIZE:       62



 DATABASES

      pgsz     dbsz   Lookaside(b)          cache  Dbname

         4       24             53         2/17/3  /data/data/com.sec.android.smthn/databases/sns.db

         4       32             55         1/13/2  /data/data/com.sec.android.smthn/databases/picasa.db

         4       36             27        10/17/3  /data/data/com.sec.android.smthn/databases/local.db

Applications Memory Usage (kB):

Uptime: 31556347 Realtime: 96096816

Check which part of portion is increasing constantly .

It could be ViewRootImpl or activity context or anything .

Above information might get you to some clue .

As told take heapdump analyse it with MAT or JHAT . Mat is awewome tool IMHO .

you should look for memory leaks caused by:

Long-lived references to an Activity, Context, View, Drawable, and other objects that may hold a reference to the container Activity or Context.
Non-static inner classes (such as a Runnable, which can hold the Activity instance).
Caches that hold objects longer than necessary.

Leak can be caused by any Object.Generally bitmaps are big. And if the out-of memory occurs very easily then you need to check on heavy objects like bitmaps.

For MAT and Leaks understanding Click this

Also this .

Also apart from above things you can also use DDMS allocation tracker to get more clue > yeah nothing can get better data than MAT .

Also check this post . Very informative

Upvotes: 1

Related Questions