sqlite+fmdb真空命令后内存泄漏(?) [英] memory leak (?) after sqlite+fmdb vacuum command

查看:49
本文介绍了sqlite+fmdb真空命令后内存泄漏(?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过 FMDB 包装器在我的应用程序中使用 sqlite.

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

在调用 VACUUM 之前,我的应用中的内存使用量为 2.25 MB:

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

[myFmdb executeUpdate: @"VACUUM;" ];

后记为 5.8 MB,我似乎无法收回内存.真空后,仪器/分配工具显示大量带有实时字节的 sqlite3MemMalloc 调用,每个调用分配 1.5 K.

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.

推荐答案

我在 sqlite-users 列表上发布了这个问题,并得到了建议减少 sqlite 缓存大小的回复.这是通过执行以下语句(根据需要调整大小值)来完成的:

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

这是释放 SQLite 内存的另一个绝妙技巧.请务必#define SQLITE_ENABLE_MEMORY_MANAGEMENT.

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

此处记录:http://www.sqlite.org/c3ref/release_memory.html

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

这篇关于sqlite+fmdb真空命令后内存泄漏(?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆