检测本机内存泄漏的Andr​​oid JNI code [英] Detecting native memory leaks in Android JNI code

查看:153
本文介绍了检测本机内存泄漏的Andr​​oid JNI code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测内存泄漏的Andr​​oid JNI code?我使用的Froyo

How to detect Memory leaks in Android JNI code? I am using Froyo

推荐答案

还有一个实验性的,不支持的功能,您可以充分利用的优势。

There is an experimental, unsupported feature that you may be able to take advantage of.

在您DDMS的配置文件(例如〜/ .android / ddms.cfg在Linux上),增加了原生=真。这使得本机堆标签。

In your DDMS configuration file (e.g. ~/.android/ddms.cfg on Linux), add "native=true". This enables the Native Heap tab.

其次,在设备上启用本地堆分配跟踪,并重新启动应用程序的框架:

Next, enable native heap allocation tracking on the device, and restart the app framework:

% adb shell setprop libc.debug.malloc 1 
% adb shell stop 
% adb shell start 

(请注意,这需要root另请注意,这仅适用于近期发布;对老版本,你还需要有libc_debug.so手动替换libc.so在设备上/系统/ lib目录)

(Note this requires root. Note also that this only applies to recent releases; on older releases you also needed to manually replace libc.so with libc_debug.so in /system/lib on the device.)

您可以告诉你,如果我不得不对看logcat的输出,同时发出一个简单的命令(亚行外壳LS)正确配置设备。如果你看到:

You can tell if you've got the device configured correctly by watching the logcat output while issuing a simple command ("adb shell ls"). If you see:

I/libc    ( 4847): ls using MALLOC_DEBUG = 1 (leak checker)

那么,你知道你已经启用了。

then you know you've enabled it.

现在,您可以使用本机堆标签功能抢到堆内存使用情况的快照。

Now you can use the Native Heap tab features to grab snapshots of heap memory usage.

DDMS会自动从你的Andr​​oid源代码树的... /符号/系统/ lib下的共享库中提取符号。当然,这需要你有一个完整的Andr​​oid源代码树,并且设备运行的是从它建成code。如果不是,则堆栈跟踪不能去coded到符号名,从而降低了功能的实用性。

DDMS will automatically extract symbols from the .../symbols/system/lib shared libraries in your Android source tree. Of course, this requires that you have a full Android source tree, and your device is running code built from it. If not, the stack traces can't be decoded to symbol names, which reduces the usefulness of the feature.

这篇关于检测本机内存泄漏的Andr​​oid JNI code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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