如何在 C++ 代码中使用 ddms 处理内存泄漏 [英] how to use ddms for memory leaks in c++ code

查看:26
本文介绍了如何在 C++ 代码中使用 ddms 处理内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用android工具DDMS解决c++代码中的内存泄漏问题我尝试通过启用 NativeHeap 拍摄快照,但我不明白快照在说什么,符号没有解析,没有显示文件名和行号.

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.

推荐答案

DDMS 中的本机堆跟踪是不受支持的隐形"功能.让它工作可能有点棘手.邮件列表中有一个较早的讨论,可能有用.

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.

如果您正在接收数据并启动 UI,那么您已经成功了一半.:-) DDMS 在特定位置查找符号,您应该能够使用 ANDROID_SYMBOLS 环境变量覆盖该符号,并使用 addr2line 将地址转换为行(它还必须能找到).

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).

查找大泄漏的最简单方法是配置 DDMS 以按库对分配进行排序.让应用程序运行一段时间,看看哪个库似乎增长最快.查看归属于该库的分配,看看是否有很多来自同一个地方.查看堆栈跟踪,看看从那里进行许多长期分配是否有意义.不是很严格,但通常可以解决问题.

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.

要更彻底地检查堆,您可以在设备上运行 valgrind,但第一次设置并不容易.

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.

这篇关于如何在 C++ 代码中使用 ddms 处理内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆