From owner-freebsd-questions@FreeBSD.ORG Wed May 20 20:16:10 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 ABA6E106566C for ; Wed, 20 May 2009 20:16:10 +0000 (UTC) (envelope-from psteele@maxiscale.com) Received: from exprod7og106.obsmtp.com (exprod7og106.obsmtp.com [64.18.2.165]) by mx1.freebsd.org (Postfix) with SMTP id 5AC978FC20 for ; Wed, 20 May 2009 20:16:10 +0000 (UTC) (envelope-from psteele@maxiscale.com) Received: from source ([209.85.198.237]) by exprod7ob106.postini.com ([64.18.6.12]) with SMTP ID DSNKShRlCnMjLIJDFMN30/r26myINKiqy7Uk@postini.com; Wed, 20 May 2009 13:16:10 PDT Received: by rv-out-0506.google.com with SMTP id l9so224589rvb.5 for ; Wed, 20 May 2009 13:16:09 -0700 (PDT) Received: by 10.140.141.16 with SMTP id o16mr810410rvd.241.1242850569937; Wed, 20 May 2009 13:16:09 -0700 (PDT) Received: from localhost ([76.231.178.131]) by mx.google.com with ESMTPS id b39sm516632rvf.5.2009.05.20.13.16.08 (version=SSLv3 cipher=RC4-MD5); Wed, 20 May 2009 13:16:08 -0700 (PDT) Date: Wed, 20 May 2009 13:16:05 -0700 (PDT) From: Peter Steele To: Dan Nelson Message-ID: <17302502.1751242850560962.JavaMail.HALO$@halo> In-Reply-To: <8793855.1731242850299553.JavaMail.HALO$@halo> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Content-Filtered-By: Mailman/MimeDel 2.1.5 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 20:16:11 -0000 I should have provided a little more detail. Even if I strip my thread function down to nothing more than this: void *mythread(void* param) { pthread_exit(NULL); } my application still grows by 128 bytes each time I spawn a thread with this function. There is no explicit memory for me to deallocate, and my understanding was that by using pthread_detach then any temporary structures allocated by the OS would be released when the thread terminates. This doesn't seem to be the case though, so I'm assuming I'm doing something wrong but I do not know what. I use the follow simple app to test this behavior: int main() { getchar(); pthread_t thread; pthread_create(&thread, NULL, mythread, NULL); getchar(); printf("done"); getchar(); } When I hit the first getchar, I check the application's size using ps from another terminal window. It shows 12312k. I then allow the application to proceed to the next getchar, and again check its size with ps. It shows 12440k. Finally, I let it proceed to the final getchar, and again ps shows 12440k. Even if I wait a while the size remains at 12440, and if I create additional threads, then each one adds to the application's footprint. What am I missing?