Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Find memory leaks from native code in android

Just wondering if someone knows how to find out memory leaks in native code from android. Google search gives lot of solution, but none of them is full. Please let me know if anybody knows how to do this.

like image 605
Anil Arrabole Avatar asked Feb 23 '11 17:02

Anil Arrabole


People also ask

How do I find memory leaks in Android?

The Memory Profiler is a component in the Android Profiler that helps you identify memory leaks and memory churn that can lead to stutter, freezes, and even app crashes. It shows a realtime graph of your app's memory use and lets you capture a heap dump, force garbage collections, and track memory allocations.

What is native memory leak?

Android's libmemunreachable is a zero-overhead native memory leak detector. It uses an imprecise mark-and-sweep garbage collector pass over all native memory, reporting any unreachable blocks as leaks. See the libmemunreachable documentation for usage instructions.

How do you find memory leaks inside apps?

If you suspect you are running into a temporal leak, a good way to check is to use Android Studio's memory profiler. Once you start a session within the profiler, take the steps to reproduce the leak, but wait for a longer period of time before dumping the heap and inspecting. The leak may be gone after the extra time.


1 Answers

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

like image 67
Anil Arrabole Avatar answered Nov 02 '22 02:11

Anil Arrabole