Originally Posted by
OReubens
if your main thread ends before all the created threads have completed, then you'll have a memory leak because all the child threads will be terminated (without allowing them proper cleanup) by the system.
a simple proof for this would be to add a 'long enough' Sleep() before your main thread ends. But this isn't a correct way to solve the actual problem.
If you create a thread, then you should have some form of synchronisation in your main thread that guarantees that ALL the worker threads have finished, before it exits to the system.
Note that if you call AfxBeginThread, then MFC will allocate a CWinThread object, if the thread isn't allowed to cleanup (or you don't do it in lieu of the normal thread cleanup), then you'll be leaking that object (at the least, potentially more).