0

My app has memory leaks,and after i used the MAT,i found two pictures.They are following: origin pics size:640*902,75.2kb

But in MAT:

Class Name                          | Shallow Heap | Retained Heap | Percentage
--------------------------------------------------------------------------------
android.graphics.Bitmap @ 0x41acff20|           40 |     9,625,656 |     18.76%
--------------------------------------------------------------------------------

Type   |Name         |Value
------------------------------
int    |mHeight      |1880
int    |mWidth       |1280
------------------------------

Problem Suspect 2
One instance of "android.graphics.Bitmap" loaded by "<system class loader>" occupies 9,625,656 (18.76%) bytes. The memory is accumulated in one instance of "byte[]" loaded by "<system class loader>".
Problem Suspect 3
One instance of "android.graphics.Bitmap" loaded by "<system class loader>" occupies 9,236,536 (18.00%) bytes. The memory is accumulated in one instance of "byte[]" loaded by "<system class loader>".

I'm using Samsung Galaxy SIII, 4.04 sdk.

And in xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/main_menu_bg"

How can i solve this problem? The Retained Heap is too large!!

JasonW
  • 495
  • 1
  • 5
  • 14
  • Hello I see some information in MAT like android.graphics.Bitmap @ 0x41acff20. Where i can see which images it is? how to view it ? – Md Maidul Islam Jan 28 '14 at 09:06
  • 1
    @Maid786 You can see this problem.[_view bitmaps from memory dump_](http://stackoverflow.com/questions/12709603/mat-eclipse-memory-analyzer-how-to-view-bitmaps-from-memory-dump/12709604#12709604) – JasonW Feb 10 '14 at 02:31

1 Answers1

1

There are couple of things you can do:

  1. As this is background image, try reducing the quality of images. I dont think it will affect the visual quality.

  2. Normally jpg images take almost half the size of png images. So, may be you can replace your png with jpg

  3. There are ways to recycle bitmaps when they are not in use. But I think in your case, it is a background image and will be required throughout till app is running. If not then consider recycling the image using recycle() api

Sushil
  • 8,250
  • 3
  • 39
  • 71
  • oh,thanks :) can you tell me ,why the png's size in memory dump is twice of the origin image? – JasonW Aug 27 '13 at 01:48
  • 1
    In the application, the png image is used as decoded bitmap thereby increasing its size. As png(an ecoding algorithm) it is an encoded image. But to use in application, we need to decode it and use as bitmap – Sushil Aug 27 '13 at 01:54