When threads are added to boost::thread_group like:
boost::thread_group my_threads;
boost::thread *t = new boost::thread( &someFunc );
my_threads.add_thread(th);
all the created boost::thread objects are deleted only when my_threads object is out of scope. But my program main thread spawns a lot of threads while execution. So if about 50 threads are already done, about 1,5Gb of memory is used by program and this memory is freed only on main process termination.
The question is: How to delete these boost::thread object when thread function is finished ?!
You could do sth like this, but mind synchronization (it is better to use shared pointer to boost::thread_group instead of reference, unless you are sure, that thread group will live long enough):
You could also check at_thread_exit() function.
Anyway, boost::thread objects should not weight 30 MB.