Thursday, August 6, 2009

Automatic Memory Leak Tracking on Android

Android provides a mechanism to track memory leakage.
In folder bionic/libc/bionic/malloc_leak.c is compiled into /system/lib/libc_debug.so, it is a memory leakage tracking version of libc.so. To enable the memory leakage tracking, replace the /system/lib/libc.so with the /system/lib/libc_debug.so.
> adb shell mv /system/lib/libc.so /system/lib/libc_original.so
> adb shell mv /system/lib/libc_debug.so /system/lib/libc.so
Before doing that, be sure to remount the system partition to 'rw'.
Use 'mv' command may have problem without libc.so, in that case use 'cp' command instead.
With the memory leak tracking, you shall see something like "MALLOC_DEBUG = 1 (leak checker)" in your logcat output.