This has been bothering me for a while now. When I try to clear a vector it just *pretends* to clear it, and the data is still in memory. This led to some obscene memory leaks, so I dug around looking for a way to really clear out a vector, and I found this:
vector<int> testVector;
// ...
// Fill testVector up with a whole bunch of ints.
// Try to clear it.
testVector.clear();
// Now swap with a new vector to *really* clear it.
vector<int>().swap(testVector);
This does work, but memory still leaks. There is an extra 56 or so bytes after the swap. So is there something that I'm missing here, or is there a better way to do this? How do I really clean out a vector so that I end up with the same amount of memory that I started with?
Sheesh, this is painful..
-Fredric