memory leak (?) after sqlite+fmdb vacuum command

2019-05-29 05:52发布

问题:

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 );


标签: ios sqlite fmdb