"Explicit termination method 'close' not called" what's means?

user3377566 picture user3377566 · Mar 4, 2014 · Viewed 7.4k times · Source

03-02 04:23:07.015: E/StrictMode(1096): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks. 03-02 04:23:07.015: E/StrictMode(1096): java.lang.Throwable: Explicit termination method 'close' not called 03-02 04:23:07.015: E/StrictMode(1096): at dalvik.system.CloseGuard.open(CloseGuard.java:184) 03-02 04:23:07.015: E/StrictMode(1096): at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:805) 03-02 04:23:07.015: E/StrictMode(1096): at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789) 03-02 04:23:07.015: E/StrictMode(1096): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694) 03-02 04:23:07.015: E/StrictMode(1096): at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:944) 03-02 04:23:07.015: E/StrictMode(1096): at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224) 03-02 04:23:07.015: E/StrictMode(1096): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188) 03-02 04:23:07.015: E/StrictMode(1096): at com.helper.database.DBOperator.queryfeeds(DBOperator.java:53) 03-02 04:23:07.015: E/StrictMode(1096): at com.example.rssreader.MainActivitySpace.getfeeddata(MainActivitySpace.java:85) 03-02 04:23:07.015: E/StrictMode(1096): at com.example.rssreader.MainActivitySpace.onActivityCreated(MainActivitySpace.java:74) 03-02 04:23:07.015: E/StrictMode(1096): at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1508) 03-02 04:23:07.015: E/StrictMode(1096): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947) 03-02 04:23:07.015: E/StrictMode(1096): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104) 03-02 04:23:07.015: E/StrictMode(1096): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682) 03-02 04:23:07.015: E/StrictMode(1096): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467) 03-02 04:23:07.015: E/StrictMode(1096): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:570) 03-02 04:23:07.015: E/StrictMode(1096): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171) 03-02 04:23:07.015: E/StrictMode(1096): at android.app.Activity.performStart(Activity.java:5253) 03-02 04:23:07.015: E/StrictMode(1096): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2149) 03-02 04:23:07.015: E/StrictMode(1096): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226) 03-02 04:23:07.015: E/StrictMode(1096): at android.app.ActivityThread.access$700(ActivityThread.java:135) 03-02 04:23:07.015: E/StrictMode(1096): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397) 03-02 04:23:07.015: E/StrictMode(1096): at android.os.Handler.dispatchMessage(Handler.java:102) 03-02 04:23:07.015: E/StrictMode(1096): at android.os.Looper.loop(Looper.java:137) 03-02 04:23:07.015: E/StrictMode(1096): at android.app.ActivityThread.main(ActivityThread.java:4998) 03-02 04:23:07.015: E/StrictMode(1096): at java.lang.reflect.Method.invokeNative(Native Method) 03-02 04:23:07.015: E/StrictMode(1096): at java.lang.reflect.Method.invoke(Method.java:515) 03-02 04:23:07.015: E/StrictMode(1096): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777) 03-02 04:23:07.015: E/StrictMode(1096): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593) 03-02 04:23:07.015: E/StrictMode(1096): at dalvik.system.NativeStart.main(Native Method)

Answer

kingston picture kingston · May 11, 2015

You need to explicitly call the close on a cursor before it goes out of scope. If you do not do it the content of the cursor and so its allocated resources won't be freed until the garbage collector will decide to actually delete it. Since the cursor requires a big amount of resources it is a good practice to close it as soon as it is not used anymore.