9
我一直在嘗試在StrictMode中運行我的應用程序,以檢查是否有可能潛行的隱藏問題。我遇到的一個問題是,在使用ContentResolver時,似乎是泄漏的DatabaseConections的誤報。Android StrictMode報告誤報
一些實驗後得到簡化爲以下兩行代碼的問題:上述
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遊標)。
有沒有人有任何洞察,如果這確實是一個誤報或真的有漏光標。
我看到類似的使用與Honeycomb一起發佈的CursorLoader API。我有一個CursorLoader(它在後臺線程中執行查詢)和一個SimpleCursorAdapter。原則上,當我從CursorLoader中交換新的遊標時,SimpleCursorAdapter應該關閉任何現有的遊標。但是,我一直看到這些遊標終結器StrictMode違規,所以這有點令人困惑。 – tomtheguvnor 2011-10-06 16:26:36