綜合一句話:vector只要clear就會真正釋放內(nèi)存僵驰;map、set工三、unordered_map只能通過malloc_trim(0)才能真正釋放內(nèi)存
方法 | map | vector | set | unordered_map |
---|---|---|---|---|
clear() | × | ? | × | × |
clear()后malloc_trim(0) | ? | ? | ? | ? |
clear()后置空容器 | × | ? | × | × |
clear()后swap | × | ? | × | × |
//置空容器
test_map = map<int, string>();
//swap
map<int, string> null_map; test_map.swap(null_map);
//或
map<int, string>().swap(test_map);