Pendyala
Pendyala

Reputation: 655

How to use Malloc Debug for checking native memory leaks?

I am exploring several options to figure out the best tool/way to find out memory leaks in native code in android app. As part of this exercise, I came across the option present in following url.

https://android.googlesource.com/platform/bionic/+/master/libc/malloc_debug/README_marshmallow_and_earlier.md

I wrote a sample app which calls a native function written in shared library. I put memory leak intentionally in this native function. Before running the app, I did

  1. adb shell setprop libc.debug.malloc.program
  2. adb shell setprop libc.debug.malloc 10

Then I started the app. But I could not see any prints in the logcat indicating memory leak.

If anybody has ever used this approach to find out the native memory leaks, could you please tell me if I am missing some thing. Is the logcat logs correct place to look for the leak messages? If not, how should I find the leak information?

Upvotes: 1

Views: 4362

Answers (1)

Akansha Pal
Akansha Pal

Reputation: 11

You are supposed to set backtrace based on the version your application has.

Try this command:

adb shell setprop libc.debug.malloc.options backtrace 

Then take dumpheap.

Upvotes: 1

Related Questions