私は自分のアプリケーションを StrictMode で実行して、潜んでいる可能性のある隠れた問題をチェックしようとしています。私が遭遇した問題の 1 つは、ContentResolver を使用しているときに Leaked DatabaseConections が誤検出されるように見えることです。
いくつかの実験の後、問題は次の 2 行のコードに単純化されました。
Cursor c = context.getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, cols, null, null, MediaStore.Video.Media.DEFAULT_SORT_ORDER);
c.close()
上記の 2 行により、次の StrictMode 違反が生成されます。
ERROR/StrictMode(26219): Releasing cursor in a finalizer. Please ensure that you explicitly call close() on your cursor:
ERROR/StrictMode(26219): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
ERROR/StrictMode(26219):
at android.database.CursorWindow.<init>(CursorWindow.java:62)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:403)
at android.content.ContentResolver.query(ContentResolver.java:302)
これは、Cursor が contentProvider によって返されたという事実に固有のものであると想定しています (したがって、直接の SQLite カーソルではありません)。
これが実際に誤検知であるか、それとも本当に漏れやすいカーソルがあるかどうか、誰かが洞察を持っていますか?