0

I have a little application, this application has seven activities, basically 6 are layouts with images and one is a MapActivity, among of 5 layouts one has a ArrayList of a internal class and each time that I use my application the memory grows to 50mb, 70mb, 111mb... I tried to call Garbage Collector but I didn't receive the expected result.

public class GC 
{    
    public static final Runtime runtime = Runtime.getRuntime();

    public static void Free()
    {
        runtime.gc();
    }
}
gandarez
  • 2,609
  • 4
  • 34
  • 47

1 Answers1

1

Have a look here: Avoid memory leaks on Android

  1. Make sure you are properly closing your other activities (this.finish).
  2. You need to remove the callbacks to images otherwise you will leak memory.

    private void unbindDrawables(View view) {
    if (view.getBackground() != null) {
        view.getBackground().setCallback(null);
    }
    if (view instanceof ViewGroup) {
        for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
            unbindDrawables(((ViewGroup) view).getChildAt(i));
        }
        ((ViewGroup) view).removeAllViews();
    }
    

Call it with the view's root (i.e. unbindDrawables(findViewById(R.id.xml_layout_root));

Community
  • 1
  • 1
YumeApps
  • 118
  • 8
  • I implemented your solution but I'm still getting over memory! I am crazy, because I don't know how can I clean memory on android application. – gandarez Feb 15 '12 at 21:51