From owner-freebsd-questions@FreeBSD.ORG Wed May 20 19:19:35 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0837B1065672 for ; Wed, 20 May 2009 19:19:35 +0000 (UTC) (envelope-from korvus@comcast.net) Received: from mx04.pub.collaborativefusion.com (mx04.pub.collaborativefusion.com [206.210.72.84]) by mx1.freebsd.org (Postfix) with ESMTP id C6B0B8FC1C for ; Wed, 20 May 2009 19:19:34 +0000 (UTC) (envelope-from korvus@comcast.net) Received: from [192.168.2.164] ([206.210.89.202]) by mx04.pub.collaborativefusion.com (StrongMail Enterprise 4.1.1.4(4.1.1.4-47689)); Wed, 20 May 2009 15:14:14 -0400 X-VirtualServerGroup: Default X-MailingID: 00000::00000::00000::00000::::151 X-SMHeaderMap: mid="X-MailingID" X-Destination-ID: freebsd-questions@freebsd.org X-SMFBL: ZnJlZWJzZC1xdWVzdGlvbnNAZnJlZWJzZC5vcmc= Message-ID: <4A1457C2.1040901@comcast.net> Date: Wed, 20 May 2009 15:19:30 -0400 From: Steve Polyack User-Agent: Thunderbird 2.0.0.21 (X11/20090327) MIME-Version: 1.0 To: Peter Steele References: <19206470.1651242845780966.JavaMail.HALO$@halo> In-Reply-To: <19206470.1651242845780966.JavaMail.HALO$@halo> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: #freebsd-questions Subject: Re: pthread_detach doesn't release memory X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 May 2009 19:19:35 -0000 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.