tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Possible pthreads memory leak



On Sun, Jan 17, 2010 at 12:01 AM, Matthew Mondor
<mm_lists%pulsar-zone.net@localhost> wrote:
> On Sat, 16 Jan 2010 23:32:35 -0600
> Zach Wegner <zwegner%gmail.com@localhost> wrote:
>
>> On Sat, Jan 16, 2010 at 10:28 PM, john heasley 
>> <heas%shrubbery.net@localhost> wrote:
>> >
>> > i think threads are attacahed by default, so you need to free the thread
>> > pointer ,etc.  pthread_destory()
>>
>> Hello John,
>>
>> I guess you mean pthread_detach()? I never thought that that was
>> needed, and reading the man pages suggests that it's equivalent to a
>> non-blocking version of pthread_join. So pthread_join should
>> theoretically do the same cleanup that pthread_detach does, after the
>> child thread exits. And indeed, calling pthread_detach after
>> pthread_join (or vice versa) still leaks memory. pthread_detach
>> returns an error too (ESRCH), as I guess it should.
>
> You're right, you shouldn't need to detach threads which you're joining
> (you'd indeed be leaking resources if you didn't join non-detached
> threads, however).
>
> I ran the same test on a recent i386 netbsd-5 and the process initially
> grows (I suspect the pthread library, and potentially the heap memory
> allocator, caches some pages/objects for performance), and then seems
> rather stable in size.  I however do see a slight size increase over
> time if running it for a long while.  However I'm still looking at the
> new size and it appears stable again at 19M/904K SIZE/RES.
>
> Thanks,
> --
> Matt
>


Hello Matt,

Well, the memory here definitely isn't stable--leaving the test
program running for a couple minutes makes the size go up to well over
a gigabyte. The resident set is more stable, it starts at about 1M but
goes up slowly, it got to about 5M before I killed it.

OTOH, I watched the total memory consumption, and the active and free
numbers stayed rather stable throughout. This might be because the
increase in the resident set was too small to change it significantly,
though.

It is strange that this doesn't happen on i386 too...

Thanks,
Zach


Home | Main Index | Thread Index | Old Index