gpt4 book ai didi

android - 追踪 SqLite 打开游标泄漏的最佳方法是什么?

转载 作者:太空狗 更新时间:2023-10-29 15:51:58 26 4
gpt4 key购买 nike

大型 android 代码块中的某处存在打开游标泄漏。超过 800 个游标打开。有谁知道查明这一点的最佳方法?有什么方法可以查询以找出游标有多少?或者有什么方法可以通过配置文件工具查看它发生在哪里?如何做到这一点?大代码块不想更改大量代码来解决此问题。我没有看到任何地方可以检查 SQLiteDatabase 类上打开的游标数。

最佳答案

在你的 onCreate 方法中试试这个

StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.penaltyLog()
.penaltyDeath()
.build());

当存在游标泄漏时,应用程序将崩溃并显示堆栈跟踪:-)

StrictMode is a developer tool which detects things you might be doing by accident and brings them to your attention so you can fix them

http://developer.android.com/reference/android/os/StrictMode.html

关于android - 追踪 SqLite 打开游标泄漏的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32599856/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com