3

Once I open my application it preserves about 7MB (Via Android Studio Memory Monitor), and during using it (Populating a listView with custom items) it pops to about 9MB : 12MB

After I close the application and use 'Initiate GC' from Android Studio it goes down to about 8.3MB.

So, does this mean / indicates that I have a memory leak?

Shouldn't it goes back to 7MB as it started?

or Shouldn't it be 0MB as my application closed?

Ashraf Alshahawy
  • 1,139
  • 1
  • 14
  • 38

1 Answers1

-1

If you are looking for delete cache of your own application then simply delete your cache directory and its all done !

public static void deleteCache(Context context) {
    try {
        File dir = context.getCacheDir();
        deleteDir(dir);
    } catch (Exception e) {}
}

public static boolean deleteDir(File dir) {
    if (dir != null && dir.isDirectory()) {
        String[] children = dir.list();
        for (int i = 0; i < children.length; i++) {
            boolean success = deleteDir(new File(dir, children[i]));
            if (!success) {
                return false;
            }
        }
        return dir.delete();
    }
    else if(dir!= null && dir.isFile())
        return dir.delete();
    else {
        return false;
    }
}

And you may require following permission to add in your manifest file in order to delete cache of other application

<uses-permission android:name="android.permission.CLEAR_APP_CACHE"/>

Reference : Clear Cache in Android Application programmatically

Community
  • 1
  • 1
  • I don't know how this code is related to my question, but in all cases, I went to application settings page via applications manager and used clear cash feature, yet, Android Studio still showing that my app allocating about 8MB. – Ashraf Alshahawy Apr 30 '16 at 11:43