how to use ddms for memory leaks in c++ code

人走茶凉 提交于 2019-12-17 19:04:56

问题


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.


回答1:


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.




回答2:


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/



来源:https://stackoverflow.com/questions/15386339/how-to-use-ddms-for-memory-leaks-in-c-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!