首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > Ruby Rails >

SQLite一次性读取过剩记录会造成内存溢出OutOfMemoryError

2012-07-03 
SQLite一次性读取过多记录会造成内存溢出OutOfMemoryErrorAndroid 2.3.3Eclipse Version: 3.7.0LogCat?Log

SQLite一次性读取过多记录会造成内存溢出OutOfMemoryError

Android 2.3.3Eclipse Version: 3.7.0LogCat

?LogCat? 报错信息:

03-15 11:34:43.163: ERROR/AndroidRuntime(17173): java.lang.OutOfMemoryError 03-15 11:34:43.163: ERROR/AndroidRuntime(17173):     at android.database.CursorWindow.getString_native(Native Method) 、03-15 11:34:43.163: ERROR/AndroidRuntime(17173):     at android.database.CursorWindow.getString(CursorWindow.java:329) 03-15 11:34:43.163: ERROR/AndroidRuntime(17173):     at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:49) 03-15 11:34:43.163: ERROR/AndroidRuntime(17173):     at com.tmall.nokia.db.RecordDBHelper.query(RecordDBHelper.java:140) 03-15 11:34:43.163: ERROR/AndroidRuntime(17173):     at com.tmall.nokia.manage.RecordDBopt.get(RecordDBopt.java:80) 03-15 11:34:43.163: ERROR/AndroidRuntime(17173):     at com.tmall.nokia.manage.RecordMessage.sendAll(RecordMessage.java:55) 03-15 11:34:43.163: ERROR/AndroidRuntime(17173):     at com.tmall.nokia.Check.run(Check.java:456) 03-15 11:34:43.163: ERROR/AndroidRuntime(17173):     at java.lang.Thread.run(Thread.java:1019)

同时有报错信息

03-15 11:30:21.763: ERROR/CursorWindow(17173): need to grow: mSize = 1048576, size = 37, freeSpace() = 5, numRows = 697403-15 11:30:21.773: ERROR/CursorWindow(17173): not growing since there are already 6974 row(s), max size 1048576 03-15 11:30:21.804: ERROR/Cursor(17173): Failed allocating 37 bytes for text/blob at 6973,3 

??或

03-15 11:34:40.463: ERROR/CursorWindow(4647): need to grow: mSize = 1048576, size = 72, freeSpace() = 18, numRows = 6974 03-15 11:34:40.473: ERROR/CursorWindow(4647): not growing since there are already 6974 row(s), max size 1048576 03-15 11:34:40.543: ERROR/CursorWindow(4647): The row failed, so back out the new row accounting from allocRowSlot 6973 03-15 11:34:40.543: ERROR/Cursor(4647): Failed allocating fieldDir at startPos 0 row 6973 
?

?

发生错误原因分析:

?

读取数据库的缓存大约为1M,CursorWindow一次性打开数据太多,造成内存溢出。

数据库中Record表的数据较多,大概有两万条,从以上错误信息,可以看出,大约读取到6974条时报错。?

?

?

解决办法:

?

先查询Record表的数据量,如果过大,做分批处理,每次处理一定量的数据,避免读取更多数据造成内存溢出。

?

1 楼 wzuying 2012-06-06   不懂吖,怎么分批啊,最多读到2600就错了,要是几万条不是读很久的吗?

热点排行