Java android.database.CursorWindowAllocationException 移动光标时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21219039/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 07:24:47  来源:igfitidea点击:

android.database.CursorWindowAllocationException when moving a Cursor

javaandroidcursorsqlite

提问by Zelig63

I'am using an SQLite database and I regularly get runtime errors I can't find the origin of. After a query, I use moveToFirstto point on the first record retrieved and this sometimes triggers an android.database.CursorWindowAllocationExceptionexception. Added to this exception is the following sentence : "Cursor window allocation of 2048kb failed.# open Cursors=736 (#cursors opendby this proc=736)".

我正在使用 SQLite 数据库,并且经常遇到无法找到来源的运行时错误。查询后,我使用moveToFirst指向检索到的第一条记录,这有时会触发android.database.CursorWindowAllocationException异常。添加到此异常的是以下句子:“2048kb 的光标窗口分配失败。# open Cursors=736 (#cursors opendby this proc=736)”。

In the Android documentation, I haven't found anything related to this exception yet. Does anyone know it's cause and a way to avoid it?

在 Android 文档中,我还没有找到与此异常相关的任何内容。有谁知道它的原因和避免它的方法?

采纳答案by NigelK

This error is nearly always due to not closing a cursor when it's finished with. Every time you open a cursor, memory is required to map the data that cursor represents and that memory cannot be released until the cursor is closed. There is a limit to the amount of memory available for this purpose so if cursors are not closed and an application continues to open new ones, this error is likely to occur at some point.

这个错误几乎总是由于游标完成后没有关闭它。每次打开游标时,都需要内存来映射游标表示的数据,并且在关闭游标之前无法释放内存。用于此目的的可用内存量是有限制的,因此如果游标没有关闭并且应用程序继续打开新的游标,则可能会在某个时候发生此错误。

I recommend you examine your code to make sure that all cursors created are being closed at some point. Also take care with any code that opens a cursor within a loop - your error message says 'open Cursors=736' which suggests a lot of cursor activity within a loop of some sort.

我建议您检查代码以确保创建的所有游标都在某个时候关闭。还要注意在循环中打开游标的任何代码 - 您的错误消息显示“open Cursors=736”,这表明在某种循环中存在大量游标活动。