Android lag after OOM crash

Viewed 14

I'm currently serving a kiosk application on a dedicated tablet.

Most of them works well, but in some uncertain cases, an OOM crashed the app.

I use the below library to revive my app with the code inside my Application class.

com.jakewharton:process-phoenix:2.0.0

 this.uncaughtException = Thread.UncaughtExceptionHandler { _, e ->
    ErrorLogger.saveError(e)
    try {

        System.gc()
        ProcessPhoenix.triggerRebirth(this)

    } catch (e: java.lang.Exception) {
        ErrorController.showError(e)
    } finally {
        Runtime.getRuntime().exit(0)
    }
 }
 Thread.setDefaultUncaughtExceptionHandler(uncaughtException)

The app revives but after it, severe lags occur.

When the app starts fresh within a rebooted tablet, it takes the app about three seconds after launch to load everything from the server and internal database. But, after when it launches after OOM, it takes about five minutes to load, as if it's suffering from low memory. AlarmManagers stop working after an ANR of the AlarmManager.

Is there a way to clean the memory or a more fresh way to restart my app?

1 Answers

Yeah- fix your OOM crash. Use less memory. Any kind of library like the one above is a bad idea- especially since you're doing it on any uncaught exception and not just OOM, meaning you could be in any kind of bad state. Just blindly trying to restart your app on any exception is a horrible idea.

In addition, there's no way to fix the slow down. The lag is because it now needs to free and reallocate almost every object in your app. That's going to be slow. Just don't do this.

Related