memory leak (?) after sqlite+fmdb vacuum command

岁酱吖の 提交于 2019-12-22 11:34:55

问题


I'm using sqlite in my app via the FMDB wrapper.

Memory usage in my app sits at 2.25 MB before a call to VACUUM:

[myFmdb executeUpdate: @"VACUUM;" ];

Afterwords its at 5.8 MB, and I can't seem to reclaim the memory. Post-vacuum, the Instruments/Allocations tool shows tons of sqlite3MemMalloc calls with live bytes, each allocating 1.5 K.

Short of closing the database and reopening it (an option), how can I clean this up?

Edit: closing and reopening the database connection does clear up the memory. This is my solution unless someone can shed some further insight to this.


回答1:


I posted this question on the sqlite-users list and got a response that suggested reducing the cache size for sqlite. This is done by executing the following statement (adjusting the size value as desired):

pragma cache_size = 100

EDIT: here's another nifty trick for releasing SQLite memory. Be sure to #define SQLITE_ENABLE_MEMORY_MANAGEMENT.

Documented here: http://www.sqlite.org/c3ref/release_memory.html

int bytesReleased = sqlite3_release_memory( 0x7fffffff );
NSLog( @"sqlite freed %d bytes", bytesReleased );


来源:https://stackoverflow.com/questions/5239040/memory-leak-after-sqlitefmdb-vacuum-command

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!