I'm trying to detect memory leaks by globally overloading new and delete for debug builds and maintaining a list of allocated blocks. This works, but incorrectly reports leaks for some static objects. For example a static std::vector itself is not allocated using new and delete but its internal buffers are. Since my detection code runs before the main function returns the destructors of these objects are not yet called so they haven't deleted their buffers yet and this appears as a "leak".
One workaround I've found is by deleting and placement newing each static object to clear out their buffers before I check for leaks:
std::vector<int> f;
f.~std::vector<int>();
new (&f) std::vector<int>();
This is really ugly though and including cleanup code that isn't required seems bad. Is there some way of getting my code to run after the statics have been destroyed? (even if it's Microsoft-specific)