pthread_detach doesn't release memory

Steve Polyack korvus at
Wed May 20 19:19:35 UTC 2009

Peter Steele wrote:
> I create a thread using something like this: 
> pthread_t thread; 
> pthread_create(&thread, NULL, mythread, NULL); 
> pthread_detach(thread); 
> I use the detach because I want to make sure the thread's resource are reclaimed when the thread completes. However, this does not seem to work. Each time I create a thread the application's memory footprint grows by 128 bytes and this memory is never released. 
> Am I doing this right? 
 From man pthread_detach:

The *pthread_detach*() function indicates that system resources for the 
specified /thread/ should be reclaimed when the thread ends. If the 
thread is already ended, resources are reclaimed immediately. *This 
routine does not cause the thread to end.

*So, unless your 'mythread' routine has successfully completed, the 
associated resources will not be reclaimed.

More information about the freebsd-questions mailing list