How to Find Memory Leaks from Native Code in Android

How to Find memory leaks from native code in android

Really useful information I got to find the leaks in native code.

  1. add native=true in ~/.android/ddms.cfg
  2. replace /system/lib/libc.so with /system/lib/libc_debug.so
    restart the framework, start DDMS, you'll see a tab native-heap

In native-heap, you can see the allocations by native code.

For more information click here

Detect memory leak in android native code

You load *.so library with System.loadLibrary, than call any jni functions. So you can define "startup" and "cleanup" functions - you can do your initialzation in former func and release all resources in latter. In this case it's possible to use any from large amount of available leak tracers - for example you can see following:

http://dmalloc.com/

http://www.andreasen.org/LeakTracer/

http://memwatch.sourceforge.net/

http://mpatrol.sourceforge.net/

About valgrind: https://stackoverflow.com/a/7815977/814297

Find memory leaks in the Activity code to free memory usage and avoid OutOfMemory Exception

Are you properly abandoning the focus listener from AudioManager?

AudioManager#abandonAudioFocus(OnAudioFocusChangeListener listener)

The actual OOM might be the result of non recycling lists as mentioned, but that could be the cause of your memory leak.

tool to check memory leaks in android

Tool "Traceview" will also be helpful to you. This comes with the android sdk.

Refer to the following link for more detail.

http://developer.android.com/guide/developing/tools/traceview.html

https://developer.android.com/studio/profile/traceview.html



Related Topics



Leave a reply



Submit