所以我具有我希望有人能夠闡明一些......我光有下面的代碼一個奇怪的問題:G ++ -static導致內存泄漏(通過命令mtrace報道)
#include <unistd.h>
#include <mcheck.h>
#include <pthread.h>
static void *run(void *args)
{
sleep(1);
return NULL;
}
int main()
{
mtrace();
pthread_t thread;
pthread_create(&thread, NULL, run, NULL);
pthread_join(thread, NULL);
return 0;
}
而且我編譯我編譯它在這2種方式:
g++ -static program.cpp -lpthread
和
g++ program.cpp -ltpthread
當我看着命令mtrace的輸出在我的CAS(mem.out E)
我看到下面當我使用-static
選項,mtrace
報道:
Memory Not freed:
__________________
Address Size Caller
0x085ac350 0x88 program.cpp:0
但是,當我排除-static
選項,mtrace
報告光榮:
No memory leaks.
所以任何想法至於這裏發生了什麼?
不確定靜態分配的東西可能會在mtrace報告泄漏後釋放靜態分配的東西。我記得_CrtDumpMemoryLeaks()發生了相同的事情; –
'int void main' ?? –
聽起來像mtrace的一個功能,試試Valgrind? –