alansa@ati-uk.com wrote:
I don't mind any one off small leaks. They may not be nice but no one is going to notice them. What bothers me is when memory keeps leaking for each iteration of the loop. <snip> Has anyone been able to confirm this leak or is it just me?
I think most people have learned from bitter experience to avoid trouble by using the DLL configuration of the CRT.
Naturally boost::threads is a dll only (at least v 1.30 which i'm currently using) and it itself can either link dynamically or statically to the crt. It doesn't make any difference which though. I have to link dynamically to crt in my program to avoid the leak. Why should this make a difference? <snip>
Multithreaded configurations of MSVCRT allocates some per-thread memory as needed, e.g. for the object that localtime returns a pointer to. To ensure that this memory is freed at thread exit, you must either use a DLL configuration of the CRT or ensure that all threads that call into it are started using the _beginthread or _beginthreadex function. The Boost.Thread DLL is not (and cannot be) linked to the same CRT that is statically linked into your executable, so neither of these conditions is satisfied. If I remember correctly, any memory allocated in your executable cannot be deallocated in the Boost.Thread DLL, or vice versa, since they have separate heaps. I would expect an attempt to do so to result in a crash, but it might in some cases be silently ignored, resulting in a leak. Ben.