Open KevinYaoooooo opened 9 years ago
Out of memory?
We really need more context. Google says this can happen if there are open cursors, but we know nothing about what the app is doing when it crashes. On Nov 2, 2015 11:06 AM, "Gray" notifications@github.com wrote:
Out of memory?
— Reply to this email directly or view it on GitHub https://github.com/j256/ormlite-android/issues/55#issuecomment-153063808 .
Fatal Exception: android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. at android.database.CursorWindow.(CursorWindow.java) at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java) at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java) at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java) at android.database.AbstractCursor.moveToPosition(AbstractCursor.java) at android.database.AbstractCursor.moveToFirst(AbstractCursor.java) at com.j256.ormlite.android.AndroidCompiledStatement.getCursor(AndroidCompiledStatement.java) at com.j256.ormlite.android.AndroidCompiledStatement.runQuery(AndroidCompiledStatement.java) at com.j256.ormlite.stmt.SelectIterator.(SelectIterator.java) at com.j256.ormlite.stmt.StatementExecutor.buildIterator(StatementExecutor.java) at com.j256.ormlite.dao.BaseDaoImpl.createIterator(BaseDaoImpl.java) at com.j256.ormlite.dao.BaseDaoImpl.iterator(BaseDaoImpl.java) at com.j256.ormlite.dao.LazyForeignCollection.seperateIteratorThrow(LazyForeignCollection.java) at com.j256.ormlite.dao.LazyForeignCollection.iteratorThrow(LazyForeignCollection.java) at com.j256.ormlite.dao.LazyForeignCollection.closeableIterator(LazyForeignCollection.java) at com.j256.ormlite.dao.LazyForeignCollection.iterator(LazyForeignCollection.java) at com.j256.ormlite.dao.LazyForeignCollection.iterator(LazyForeignCollection.java) at com.misfit.home.models.Scene.getStanderPositions(Scene.java) at com.misfit.home.ui.widgets.MultiSceneAdapter.attemptSetColorCircles(MultiSceneAdapter.java) at com.misfit.home.ui.widgets.MultiSceneAdapter.displayScene(MultiSceneAdapter.java) at com.misfit.home.ui.widgets.MultiSceneAdapter.onBindViewHolder(MultiSceneAdapter.java) at com.misfit.home.ui.widgets.MultiSceneAdapter.onBindViewHolder(MultiSceneAdapter.java) at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java) at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java) at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java) at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java) at android.support.v7.widget.LinearLayoutManager.scrollBy(LinearLayoutManager.java) at android.support.v7.widget.LinearLayoutManager.scrollVerticallyBy(LinearLayoutManager.java) at android.support.v7.widget.RecyclerView$ViewFlinger.run(RecyclerView.java) at android.view.Choreographer$CallbackRecord.run(Choreographer.java) at android.view.Choreographer.doCallbacks(Choreographer.java) at android.view.Choreographer.doFrame(Choreographer.java) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java) at android.os.Handler.handleCallback(Handler.java) at android.os.Handler.dispatchMessage(Handler.java) at android.os.Looper.loop(Looper.java) at android.app.ActivityThread.main(ActivityThread.java) at java.lang.reflect.Method.invoke(Method.java) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
By context I mean what is your app doing. Need to see some code and possibly how you're making calls. My rough guess is you're either closing your SQliteOpenHelper, or since you've got a lazy foreign collection, you're making too many cursors and blowing up something. It would seem each entry in the adapter is making a lazy call.
On Mon, Nov 2, 2015 at 8:30 PM, Kevin Yao notifications@github.com wrote:
Fatal Exception: android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. at android.database.CursorWindow.(CursorWindow.java) at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java) at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java) at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java) at android.database.AbstractCursor.moveToPosition(AbstractCursor.java) at android.database.AbstractCursor.moveToFirst(AbstractCursor.java) at com.j256.ormlite.android.AndroidCompiledStatement.getCursor(AndroidCompiledStatement.java) at com.j256.ormlite.android.AndroidCompiledStatement.runQuery(AndroidCompiledStatement.java) at com.j256.ormlite.stmt.SelectIterator.(SelectIterator.java) at com.j256.ormlite.stmt.StatementExecutor.buildIterator(StatementExecutor.java) at com.j256.ormlite.dao.BaseDaoImpl.createIterator(BaseDaoImpl.java) at com.j256.ormlite.dao.BaseDaoImpl.iterator(BaseDaoImpl.java) at com.j256.ormlite.dao.LazyForeignCollection.seperateIteratorThrow(LazyForeignCollection.java) at com.j256.ormlite.dao.LazyForeignCollection.iteratorThrow(LazyForeignCollection.java) at com.j256.ormlite.dao.LazyForeignCollection.closeableIterator(LazyForeignCollection.java) at com.j256.ormlite.dao.LazyForeignCollection.iterator(LazyForeignCollection.java) at com.j256.ormlite.dao.LazyForeignCollection.iterator(LazyForeignCollection.java) at com.misfit.home.models.Scene.getStanderPositions(Scene.java) at com.misfit.home.ui.widgets.MultiSceneAdapter.attemptSetColorCircles(MultiSceneAdapter.java) at com.misfit.home.ui.widgets.MultiSceneAdapter.displayScene(MultiSceneAdapter.java) at com.misfit.home.ui.widgets.MultiSceneAdapter.onBindViewHolder(MultiSceneAdapter.java) at com.misfit.home.ui.widgets.MultiSceneAdapter.onBindViewHolder(MultiSceneAdapter.java) at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java) at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java) at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java) at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java) at android.support.v7.widget.LinearLayoutManager.scrollBy(LinearLayoutManager.java) at android.support.v7.widget.LinearLayoutManager.scrollVerticallyBy(LinearLayoutManager.java) at android.support.v7.widget.RecyclerView$ViewFlinger.run(RecyclerView.java) at android.view.Choreographer$CallbackRecord.run(Choreographer.java) at android.view.Choreographer.doCallbacks(Choreographer.java) at android.view.Choreographer.doFrame(Choreographer.java) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java) at android.os.Handler.handleCallback(Handler.java) at android.os.Handler.dispatchMessage(Handler.java) at android.os.Looper.loop(Looper.java) at android.app.ActivityThread.main(ActivityThread.java) at java.lang.reflect.Method.invoke(Method.java) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
— Reply to this email directly or view it on GitHub https://github.com/j256/ormlite-android/issues/55#issuecomment-153211690 .
Kevin Galligan http://about.me/kpgalligan
I am using fabric for tracking crash. I got same exception. When i try to run "contentsDao.queryForAll();"
My code : private Dao<L_Content, Integer> contentsDao; . . . . public List getAllContents(String searchQuery) { try { if (searchQuery == null) { return contentsDao.queryForAll(); } else { if (contentsQuery == null) { contentsQuery= makeContentsQuery(false); } String nameParameter = searchQuery == null ? "%%" : "%"+searchQuery.trim()+"%"; contentsQuery.setArgumentHolderValue(0,nameParameter); return contentsDao.query(contentsQuery); } } catch (SQLException e){ e.printStackTrace(); return null; } } . . . .
Logcat output :
Fatal Exception: android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed.
at android.database.CursorWindow.
Different things can cause the issue, but the summary is it tried to allocate 2M for the cursor window and failed. I've recently become very familiar with this part of the api. It can fail because you're out of memory, but I would imagine other situations. Its not an ormlite thing, though. Its deep android. More code context would be helpful. Probably better to post to stackoverflow, though.
I would make sure the connection hasn't been closed for some reason. It looks like its a field on that object. If you're opening/closing your db but caching the dao, I think you can run into problems.
Also, not to nitpick, but the first part of this statement can be removed:
String nameParameter = searchQuery == null ? "%%" : "%"+searchQuery.trim()+"%";
If searchQuery is null, you've already returned from the method.
On Mon, May 30, 2016 at 9:11 AM, gunessoley notifications@github.com wrote:
I am using fabric for tracking crash log. I got same exception. When i try to run "contentsDao.queryForAll();"
My code : private Dao contentsDao; . . . . public List getAllContents(String searchQuery) { try { if (searchQuery == null) { return contentsDao.queryForAll(); } else { if (contentsQuery == null) { contentsQuery= makeContentsQuery(false); } String nameParameter = searchQuery == null ? "%%" : "%"+searchQuery.trim()+"%"; contentsQuery.setArgumentHolderValue(0,nameParameter); return contentsDao.query(contentsQuery); } } catch (SQLException e){ e.printStackTrace(); return null; } }
Logcat output :
Fatal Exception: android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. at android.database.CursorWindow.(CursorWindow.java:108) at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:198) at android.database.sqlite.SQLiteCursor.clearOrCreateWindow(SQLiteCursor.java:316) at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:142) at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:136) at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:197) at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:237) at com.j256.ormlite.android.AndroidCompiledStatement.getCursor(AndroidCompiledStatement.java:163) at com.j256.ormlite.android.AndroidCompiledStatement.runQuery(AndroidCompiledStatement.java:57) at com.j256.ormlite.stmt.SelectIterator.(SelectIterator.java:55) at com.j256.ormlite.stmt.StatementExecutor.buildIterator(StatementExecutor.java:232) at com.j256.ormlite.stmt.StatementExecutor.query(StatementExecutor.java:181) at com.j256.ormlite.stmt.StatementExecutor.queryForAll(StatementExecutor.java:113) at com.j256.ormlite.dao.BaseDaoImpl.queryForAll(BaseDaoImpl.java:239) at ak.detaysoft.yeryuzudergidis.DatabaseApi.getAllContents(DatabaseApi.java:469) at ak.detaysoft.yeryuzudergidis.DataApi.isLibraryMustBeEnabled(DataApi.java:201) at com.artifex.mupdfdemo.MuPDFActivity.onKeyDown(MuPDFActivity.java:2414) at android.view.KeyEvent.dispatch(KeyEvent.java:3147) at android.app.Activity.dispatchKeyEvent(Activity.java:2831) at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2438) at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4582) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4537) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4068) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4121) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4087) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4201) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4095) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4258) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4068) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4121) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4087) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4095) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4068) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4121) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4087) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4234) at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:4421) at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2480) at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:2074) at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:2065) at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:2457) at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141) at android.os.MessageQueue.nativePollOnce(MessageQueue.java) at android.os.MessageQueue.next(MessageQueue.java:143) at android.os.Looper.loop(Looper.java:130) at android.app.ActivityThread.main(ActivityThread.java:5942) at java.lang.reflect.Method.invoke(Method.java) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/j256/ormlite-android/issues/55#issuecomment-222489760, or mute the thread https://github.com/notifications/unsubscribe/AAELIJ4mj9QAPUteoopxj5fc3T8zxbsTks5qGuIfgaJpZM4GZ7mr .
Kevin Galligan http://about.me/kpgalligan
Share the Motorhead: https://www.youtube.com/playlist?list=PL0mtSKSOY5MtzRWJnJh3FAVBR9ynCMe2W
@kpgalligan thanks for your attention. Second "searchQuery == null" if clause is unnecessary. I will remove this line.
This method is used thousands times a day. But this exception occured once time. Maybe its a android or memory bug. I will open an issue on stackoverflow.
Not sure it'll help, but I've seen this recently myself, but in a wildly different context.
Each Cursor has a CursorWindow, which is where the raw data is copied. Each CursorWindow gets 2M. If you have a lot of open Cursor objects, you can pretty quickly rack up memory usage. You could in theory do this with a deep eager fetch, as each runs a query, but by default Ormlite doesn't really go very deep before a killswitch stops (again, by default).
Its probably something else, though.
On Tue, May 31, 2016 at 4:29 AM, gunessoley notifications@github.com wrote:
@kpgalligan https://github.com/kpgalligan thanks for your attention. Second "searchQuery == null" if clause is unnecessary. I will remove this line.
This method is used thousands of times a day. But this exception occured once time. Maybe its a android or memory bug. I will open an issue on stackoverflow.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/j256/ormlite-android/issues/55#issuecomment-222624338, or mute the thread https://github.com/notifications/unsubscribe/AAELIEXAN4UonBF7mQosC4eNKuCpjV3_ks5qG_FdgaJpZM4GZ7mr .
Kevin Galligan http://about.me/kpgalligan
Share the Motorhead: https://www.youtube.com/playlist?list=PL0mtSKSOY5MtzRWJnJh3FAVBR9ynCMe2W
Also, not sure what this is for, but in general if you get an exception once and its not repeatable, I wouldn't lose a whole lot of sleep over it. Depends on the app, though, I guess.
On Tue, May 31, 2016 at 11:28 AM, Kevin Galligan kgalligan@gmail.com wrote:
Not sure it'll help, but I've seen this recently myself, but in a wildly different context.
Each Cursor has a CursorWindow, which is where the raw data is copied. Each CursorWindow gets 2M. If you have a lot of open Cursor objects, you can pretty quickly rack up memory usage. You could in theory do this with a deep eager fetch, as each runs a query, but by default Ormlite doesn't really go very deep before a killswitch stops (again, by default).
Its probably something else, though.
On Tue, May 31, 2016 at 4:29 AM, gunessoley notifications@github.com wrote:
@kpgalligan https://github.com/kpgalligan thanks for your attention. Second "searchQuery == null" if clause is unnecessary. I will remove this line.
This method is used thousands of times a day. But this exception occured once time. Maybe its a android or memory bug. I will open an issue on stackoverflow.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/j256/ormlite-android/issues/55#issuecomment-222624338, or mute the thread https://github.com/notifications/unsubscribe/AAELIEXAN4UonBF7mQosC4eNKuCpjV3_ks5qG_FdgaJpZM4GZ7mr .
Kevin Galligan http://about.me/kpgalligan
Share the Motorhead: https://www.youtube.com/playlist?list=PL0mtSKSOY5MtzRWJnJh3FAVBR9ynCMe2W
Kevin Galligan http://about.me/kpgalligan
Share the Motorhead: https://www.youtube.com/playlist?list=PL0mtSKSOY5MtzRWJnJh3FAVBR9ynCMe2W
I'm going to close this. Feel free to reopen if necessary.
I am going through the same issue. I am accessing DB every 5 seconds and if I stay on the same page for long I get this error.I don't know how to fix this. I searched a lot but didn't find a solution yet.
Logcat:
E/AndroidRuntime: FATAL EXCEPTION: main
android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed.
at android.database.CursorWindow.
This problem appeared in my project too.
any fixes?
@erSAurabhSA, By observing the stack trace, it is failed to allocate memory while instantiating the CursorWindow object. I think, it is OOM. As you are able to reproduce this every time, profile your memory usage in Android Studio and check for hotspots in your application.
any fixes finally ?
I'm not an Android specialist so I'm not sure what is going on. This site might help: http://stevevallay.github.io/blog/2014/11/17/memory-leak/
Questions:
Fatal Exception: android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. at android.database.CursorWindow.(CursorWindow.java) at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java) at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java) at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java) at android.database.AbstractCursor.moveToPosition(AbstractCursor.java) at android.database.AbstractCursor.moveToFirst(AbstractCursor.java) at com.j256.ormlite.android.AndroidCompiledStatement.getCursor(AndroidCompiledStatement.java) at com.j256.ormlite.android.AndroidCompiledStatement.runQuery(AndroidCompiledStatement.java) at com.j256.ormlite.stmt.SelectIterator.(SelectIterator.java) at com.j256.ormlite.stmt.StatementExecutor.buildIterator(StatementExecutor.java) at com.j256.ormlite.dao.BaseDaoImpl.createIterator(BaseDaoImpl.java) at com.j256.ormlite.dao.BaseDaoImpl.iterator(BaseDaoImpl.java) at com.j256.ormlite.dao.LazyForeignCollection.seperateIteratorThrow(LazyForeignCollection.java) at com.j256.ormlite.dao.LazyForeignCollection.iteratorThrow(LazyForeignCollection.java) at com.j256.ormlite.dao.LazyForeignCollection.closeableIterator(LazyForeignCollection.java) at com.j256.ormlite.dao.LazyForeignCollection.iterator(LazyForeignCollection.java) at com.j256.ormlite.dao.LazyForeignCollection.iterator(LazyForeignCollection.java)