how to use android tool DDMS for memory leaks in c++ code i tried, by taking snapshots with NativeHeap enabled, but i am not understanding what snapshots are saying, and symbols are not resolving , no file names and line numbers are shown.
2 Answers
Native heap tracking in DDMS is an unsupported "stealth" feature. Getting it to work can be a bit tricky. There's an older discussion on a mailing list that may be useful.
If you're receiving data and have the UI up, you're halfway there. :-) DDMS looks for symbols in a specific location which you should be able to override with the ANDROID_SYMBOLS
environment variable, and converts addresses to lines with addr2line
(which it must also be able to find).
The simplest way to look for big leaks is to configure DDMS to sort the allocations by library. Let the app run for a while and see which library seems to be growing the fastest. Look at the allocations attributed to that library and see if there's a lot that are coming from the same place. Look at the stack trace and see if it makes sense to have many long-lived allocations from there. Not very rigorous, but it often does the trick.
For a more thorough examination of the heap, you can run valgrind on the device, but that's not any easier to set up the first time.

- 51,356
- 5
- 116
- 166
-
I used debug symbols, and now symbols are getting resolved, and showing up the function names, addresses and line numbers of the code. Now i am running the app, and used one feature say for example: open about option and see the information about the app, (version, credits), links to rate the app kind of items, and back to the app from about view. Now in this scenario is it possible to find the leak. – vsmph Mar 18 '13 at 14:04
-
1If you repeat the process 10 times, and you're leaking objects every time, you should see 10 copies of an allocation with the same stack trace. It's more effective if you can "checkpoint" an earlier run and diff the allocations, but sometimes the problem will leap out at you just by looking at the allocations. If it's useful, you can get the "raw" data with `adb shell am dumpheap -n
/sdcard/dump.txt`. – fadden Mar 18 '13 at 16:43 -
Thanks a lot. It worked fine, and i found really big good leaks with this. ----------------------------- For some cases , where i can NOT run a scenario multiple times, like log-in with user id. kind of cases are not able to cover. Any suggestions for these cases is welcome . – vsmph Apr 04 '13 at 10:34
-
You can specify the path to `addr2line` with this environment variable: `ANDROID_ADDR2LINE` – Kyle Apr 10 '16 at 17:50
Use Allocation tracker. Here is great talk about finding memory leaks in Android: http://www.youtube.com/watch?v=_CruQY55HOk
And here you have a blog post about it: http://www.curious-creature.org/2009/02/07/track-memory-allocations-on-android/

- 4,119
- 1
- 22
- 32
-
2Blog post is very useful to understand concept of memory leaks.. just now i tried the post , it is showing the allocations in java code. but i am looking for something which works for c++ code. – vsmph Mar 13 '13 at 13:38