来源:https://stackoverflow.com/questions/38469966/leveldb-limit-testing-limit-memory-used-by-a-program
Perhaps there is no need in reducing available memory, but simply disable cache as described here:
leveldb::ReadOptions options;
options.fill_cache = false;
leveldb::Iterator* it = db->NewIterator(options);
for (it->SeekToFirst(); it->Valid(); it->Next()) {
...
}
设置选项 options.fill_cache = false;
可以降低在遍历索引时的内存使用量。但是呢,经过测试,在遍历过程中,并没有少申请内存,而是在遍历结束后,内存自动下降了很多。