对数据库中的SQLiteConnection对象被泄露!请确定您的应用程序 [英] A SQLiteConnection object for database was leaked! Please fix your application

查看:507
本文介绍了对数据库中的SQLiteConnection对象被泄露!请确定您的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序给我这个警告

My application give me this warning

有关数据库中的SQLiteConnection对象   +数据+数据+ com_example_test +数据库被泄露!请修正   您的应用程序结束正在进行的交易正常,并关闭   当不再需要该数据库。

A SQLiteConnection object for database '+data+data+com_example_test+database' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.

不过,我每次使用后关闭数据库对象和光标。

But I close the db object and the cursor after every use.

        try {
            while (cursor.moveToNext()) {
              ...
            }
        } finally {
            if (cursor != null && !cursor.isClosed())
                cursor.close();
        }

...
    db.close();

你能帮助我的理解是什么问题? 谢谢!

Can you help me for understand what is the problem? thanks!!!

更新! 我尝试从这个帖子该解决方案 <一href="http://stackoverflow.com/questions/18147354/sqlite-connection-leaked-although-everything-closed/18148718#18148718">SQLite连接泄露虽然一切封闭

UPDATE! I try this solution from this post SQLite Connection leaked although everything closed

和我没有内存泄漏了,它是一个很好的解决方案?

and I don't have memory leak anymore, is it a good solution?

推荐答案

可能的解决方案 ::

  • 您有未提交的事务您已经启动了(你应该 始终关闭交易,一旦你开始)
  • 检查您是否已经关闭您已经打开,如果你的光标 使用 sqlite的(看起来像你这样做从您发布的code这一步)
  • 同时移动 db.close 最后
  • You have not committed the transactions you have started (You should always close the transaction once you started)
  • Check whether you have closed the cursors you have opened if you are using Sqlite (Looks like you have done this step from the code you posted)
  • Also move the db.close to finally block

这篇关于对数据库中的SQLiteConnection对象被泄露!请确定您的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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