http://jdoc.iteye.com/blog/1217804
http://valgrind.org/docs/manual/ms-manual.html
http://manyhappy163.blog.163.com/blog/static/16447683120105174149969/
http://hi.baidu.com/algorithms/item/77e5c6bfed350d77244b097f
经过调查,结论是:
1。map不能使用swap的方式来强制释放内存;
2。map用的allocator,新版gcc用new_allocator,不存在pool的问题;
3。根本原因是free函数(libc内部实现),并没有把你内存真正的释放,这个与free的内部实现机制有关了。
下面是一个小的测试程序
$ cat test_mem_seg.cpp
#include <vector>
#include <malloc.h>
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
int main(int argc, char* argv[]) {
std::vector<void*> v;
int block_len = 120;
if (argc > 1) {
block_len = atoi(argv[1]);
}
for (int i = 0; i < 1024 * 1024; ++i) {
char* p = (char*)malloc(block_len);
sprintf(p, "%d", i);
v.push_back(p);
}
std::cout << "\n===============malloc (block unit size:" << block_len << ") ok==============\n";
malloc_stats();
for (int i = 0; i < 1024 * 1024; ++i) {
free(v[i]);
}
std::cout << "\n===============free (block unit size:" << block_len << ") ok==============\n";
malloc_stats();
}