Microsoft's CRT memory leak detector indeed shows leaks (of course after I put the sf::RenderWindow declaration in a local block; checking something before its destruction is pointless).
I also tested the code with my self-written memory tool. When I called the tool's report functions, three memory leaks were observed (24, 20 and 4 bytes). These are the same ones as the CRT stated.
But, according to my trace, that memory
is freed – the deallocation took place after my function call, so the memory isn't considered freed at report time. I think, Microsoft's memory dump has got the same problem.
By the way, those alleged leaks came up in the following functions:
- sf::Resource<T>::Resource() – the std::set initialization
- sf::ThreadLocal::ThreadLocal(void*) – myImpl = new priv::ThreadLocalImpl;
- sf::Mutex::Mutex() – myMutexImpl = new priv::MutexImpl;
Obviously, this memory is all correctly deallocated. The above constructors are invoked during program startup, before main(). Therefore, the deallocation is performed at program shutdown, after main().
So: Decide wisely which memory observation tool you want to trust.