jeudi 25 février 2021

RAM leaks on stl containers?

I have a RAM limit on my project, as it contains a lot of data manipulation . The problem is, I noticed that calling std::set<std::pair<int64_t, int64_t>>::clear() does not actually free any memory. The code for reproducing the problem:

std::set<std::pair<int64_t, int64_t>> stltest;
for (size_t i=1; i<=250000; i++)
{
    stltest.insert({i, i});
}
std::cout << " "; // place for a breakpoint
stltest.clear();
std::cout << " "; // place for a breakpoint

On ubuntu 20.04, standart c++ compiler this thing takes 17,7 MB and it doesn't give it back. Probably clear() just sets size() to zero, but does nothing with contents, which is weird. Am I dumb or am I dumb? Can I get the memory back, I really need it.

Edit: Tried to manually create new and delete after and still can't get my memory back.

Aucun commentaire:

Enregistrer un commentaire