#include <iostream>
#include <boost/thread/thread.hpp>
#include <malloc.h>
class callable {
public:
void operator()() {
std::cout << "Thread Run" << std::endl;
}
}
void run() {
callable c;
boost::thread t(boost::ref(c));
t.join();
}
int main() {
int alloc = mallinfo().uordblks;
run();
int leaked = mallinfo().uordblks - alloc;
if(leaked)
std::cout << "mem leak: " << leaked << std::endl;
return 0;
}
它确实在屏幕上打印“mem leak: 336”,有人可以解释为什么吗?我希望“泄漏”为0。