Page 1 of 1

FreeThread() to close OS handle?

Posted: Tue Jun 24, 2008 8:52 am
by dige
I've got a hint from Danilo, that every thread create a thread object which remains in the system until the thread has terminated and all handles to it have been closed through a call to CloseHandle_().
(German pb board: http://www.purebasic.fr/german/viewtopic.php?t=16950 )
If you dont close it with CloseHandle_ (ThreadID), it still stays open, lacks memory und increase the user objects counter.

Another thing is, you can get the exit code from the thread via that handle:
GetExitCodeThread(
HANDLE hThread, // handle to the thread
LPDWORD lpExitCode // address to receive termination status
);

Posted: Tue Jun 24, 2008 12:49 pm
by Fred
I already answered on IRC, but i will put it here as well: there is no leak, as every CreateThread() has a cleanup routine which check for finished threads and properly close their handle.