-
-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory not reclaimed after calling map.clear() #237
Comments
Hi @marioroy , if you want to guarantee that your map is cleared, you can swap it with a temporary map, for example: MyMap map;
map.emplace(....);
...
MyMap().swap(map); // swap map with an empty temporary, which is immediately destroyed |
Thank you. Your suggestion works. |
Hi, @greg7mdp. I met to ask another question. Is it possible to clear/destroy a sub map individually, inside the top-level parallel loop? This will help minimize total memory consumption. // Store the properties into a vector
vec_str_int_type propvec;
size_t prev_num_keys;
propvec.resize(map.size());
std::vector<vec_str_int_type::iterator> I; I.resize(map.subcnt());
I[0] = propvec.begin();
for (size_t i = 0; i < map.subcnt(); ++i) {
map.with_submap(i, [&](const map_str_int_type::EmbeddedSet& set) {
if (i == 0) {
prev_num_keys = set.size();
} else {
I[i] = I[i-1] + prev_num_keys;
prev_num_keys = set.size();
}
});
}
#pragma omp parallel for schedule(static, 1) num_threads(4)
for (size_t i = 0; i < map.subcnt(); ++i) {
map.with_submap(i, [&](const map_str_int_type::EmbeddedSet& set) {
auto it = I[i];
for (auto& x : set)
*it++ = std::make_pair(std::move(x.first), x.second);
// here, I like to reclaim memory after the inner-for-loop completes
});
}
// swap map with an empty temporary, which is immediately destroyed
map_str_int_type().swap(map); |
Ah, the vector is already fully allocated initially. Never mind. The maximum memory consumption is reached. I'm updating the llil4map demonstrations and checking |
Hi, @greg7mdp. I recall
map.clear()
releasing the memory immediately. This stopped working and unsure if occurred around PR #205. So now, the memory is not reclaimed at the OS level until the application exits. I miss the priormap.clear()
behavior.I reverted a little bit and now see memory reclaimed.
I wish map.clear() accepted a boolean
map.clear(true)
to do the prior behaviorif (bool_destroy && capacity_ > 127)
.The text was updated successfully, but these errors were encountered: