2

I am beginner to Android development. There are several screens in my app and I can navigate back and forth between these screen using "backstack" feature. As I traverse through the app in depth, the memory usage of app is increasing. Sometimes it reaches up to 100 MB..!! It causes app to restart.

As I understand, below may be, possible reasons behind memory overuse:

1) App makes heavy use of images.

2) Backstacking is implemented. (There is only once activity used and other are fragments)

3) There is one background service running continuously for that app.

I am not sure whether these are the actual reasons. Please help me to find out the reasons. Any tips regarding memory overuse problem? One more question, What should be the ideal memory usage of Android app?

Andrei
  • 42,814
  • 35
  • 154
  • 218
Tejas Sutar
  • 747
  • 2
  • 11
  • 33
  • take a look at: http://stackoverflow.com/questions/21795645/exception-outofmemoryerror/21950787#21950787 and http://stackoverflow.com/questions/22043232/out-of-memory-exception-with-custom-gridview/22043466#22043466 and the links therein – Pararth Feb 27 '14 at 07:22

1 Answers1

0

call these two method in your app it will delete all cache of images from android data and ur app will not crashed from memory issue

//this is for clear cache folder in android -> data folder which generate by gallry lazy loading 
        public static void trimCache(Context context) {
            try {
    //         File dir = context.getCacheDir();
               File dir = context.getExternalCacheDir();
               if (dir != null && dir.isDirectory()) {
                  deleteDir(dir);
                  System.out.println("delete cache folderrrrrrrrrr");
               }
            } catch (Exception e) {
               // TODO: handle exception
            }
         }
        public static void trimCacheinternal(Context context) {
            try {
                File dir = context.getCacheDir();
    //          File dir = context.getExternalCacheDir();
                if (dir != null && dir.isDirectory()) {
                    deleteDir(dir);
                    System.out.println("delete cache folderrrrrrrrrr");
                }
            } catch (Exception e) {
                // TODO: handle exception
            }
        }
Bhanu Sharma
  • 5,135
  • 2
  • 24
  • 49