Fd 泄漏检测

Android系统每个进程创建的file descriptors 不能超多1024个。

查看某个进程FD数量的方法

adb shell lsof | grep <your-pid> | wc -l

常见的会创建FD的几个地方,使用完毕需要释放相关资源

文件输入输出流 XXInput/OutStream,需要close

Socket,需要close

数据库资源Cursor,需要close

Looper.prepare,HandlerThread,需要Looper.quit

参考资料:

Android Memory and File Descriptor Leaks, Diagnosis and Debugging: Android Memory and File Descriptor Leaks, Diagnosis and Debugging

Fd leak in Android: http://huzhengyu.com/2017/01/21/Fd-leak-in-Android/

扫描二维码关注公众号,回复: 13500856 查看本文章

fd 泄漏可以通过统计proc下fd数目观察是否持续增长来判断是否存在泄漏

查看方法:

1.获取进程id

ps | grep "包名"

2.统计当前进程fd数目

ls -l /proc/"进程号"/fd | wc -l

猜你喜欢

转载自blog.csdn.net/cpcpcp123/article/details/121653494
fd