0

I have a crash for which I receive the following report in Google Play.

java.lang.OutOfMemoryError: [memory exhausted]
at dalvik.system.NativeStart.main(Native Method)

As you can see, not a lot of information. There is this question that asks the same thing but I don't believe the answer of ignoring it is acceptable.

The fact there is nothing about my application in the stack trace suggests that it's the OS that's not allowing the application to start. This implies there isn't much we can do however, even after users have rebooted their devices, they still cannot open the application. My application isn't big: 22.20MB on the device.

Please see the following or the crash report stats.

OOM Crash Report Stats

Is there anything I can do to rectify this or at least minimise the chances of this happening?

Community
  • 1
  • 1
StuStirling
  • 15,601
  • 23
  • 93
  • 150
  • Is you Application working well in Debugging mode ? – Salman Khakwani Mar 30 '15 at 13:29
  • Yes it works fine. I've not been able to recreate this problem and have never seen it before. – StuStirling Mar 30 '15 at 13:30
  • You may try this http://stackoverflow.com/questions/11275650/how-to-increase-heap-size-of-an-android-application. I hope this helps. – Salman Khakwani Mar 30 '15 at 13:37
  • Are you trying to load a lot of bitmaps at once (like an array) or maybe a large one? – DevJem Mar 30 '15 at 13:39
  • without information about the structure of you app, manifest, content of onStart() etc... we can only guess... – alex Mar 30 '15 at 13:45
  • My first guess (yeah, an outright guess), would be that you are loading a lot of something into memory. It might work fine in your debugger, because in your test environment, you aren't loading as much, not as many apps are running as in the production environment, and/or you have more RAM than the devices that are failing. Assuming the amount of data (images, other data) you are loading is the same as production--look at how much you are loading as the source of your problem. – Russ Mar 30 '15 at 13:52
  • @Russ have run a launch through the memory monitor and can see it takes 30MB of memory on start up. Where would I start at looking to decrease this? – StuStirling Apr 01 '15 at 11:31

1 Answers1

0

Don't know if its a right solution or not but it solved my issue. The common reason of java.lang.OutOfMemoryError is overflowing the limit of cache. What I did, I have cleared the Application cache on the launcher activity. So whenever the application is launched at first it clears the cache.

add this methods out side of the onCreate method of your launcher activity.

//Following two methods are used to clear the Cache memory of this application
public static void deleteCache(Context context) {
    try {
        File dir = context.getCacheDir();
        if (dir != null && dir.isDirectory()) {
            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();
}

And call deleteCache(this); inside of the onCreate.

Mohammad Arman
  • 7,020
  • 2
  • 36
  • 50