#include #include #include boost::thread th; int main(){ for(auto ti=0; ti<100000; ti++){ th.detach(); th = //commenting this line fixes the memory issue boost::thread([ti](){ std::cout << ti << std::endl; }); } std::string st; std::cin >> st; return 0; }