Solution overview
The idea is to store the application heap if an out of memory error happens. The HPROF file can be then analyzed using Eclipse Memory Analyzer Tool that I will present later.
Step 1: Create a class that implements Thread.UncaughtExceptionHandler
The implemented method uncaughtException will check if the exception is out of memory and if it's the case, the HPROF file will be dumped in the device storage.Step 2: Set the uncaught exception handler the thread we want to create the heap dump
It's very sample, we can either set the uncaught exception handler to the main thread:Or, to any running thread:
Komentar
Posting Komentar