I'm messing around with some threads in preparation for some server work I will do. I'm checking for memory leaks with some simple looping code. I noticed that running some code caused a memory leak. The code I assumed was leak proof as it was very simple. So I tried again but this time without any code, just a empty function and I'm still getting the same results.
#include <thread>
#include <windows.h>
void doNothing() {}
int main() {
for (int i = 0; i < 10000; i++) {
std::thread thread_obj(doNothing);
thread_obj.join();
}
Sleep(10000000); // <- this sleep here is just so I can monitor the memory in Visual Studio 2019
return 0;
}
Here's the memory usage graph. The point where it flattens out is when it hits the sleep
Heap size after hitting the sleep
And here's the Stack view. Here I'm getting some puzzling results.
Can anyone explain what I'm doing wrong?
I am using x64, Visual Studio 2019 16.5.2
If the answer is obvious, or I'm doing something stupid - I apologise in advance, as this issue seems so fundamental I'm 99% sure I'm doing something wrong.