ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
When a joinable thread terminates, its memory resources
(thread descriptor and stack) are not deallocated until
another thread performs pthread_join on it. Therefore,
pthread_join must be called once for each joinable thread
created to avoid memory leaks.
However, I found that it does not deallocate the resources, at least in njamd's opinion (but I personally do beleive njamd). Does anyone know what it the reason and how to force the freeing?
thread started
good bye
0x4213c000-0x4213e000: Aligned len 68
Allocation callstack:
called from ./a.out(pthread_join+0x12e)[0x80484e2]
called from /lib/tls/libc.so.6(__libc_start_main+0xe4)[0x420157a4]
called from ./a.out(pthread_join+0x41)[0x80483f5]
Not Freed
NJAMD totals:
Allocation totals: 1 total, 1 leaked
Leaked User Memory: 68 bytes
Peak User Memory: 68 bytes
NJAMD Overhead at peak: 7.934 kB
Peak NJAMD Overhead: 7.934 kB
Average NJAMD Overhead: 7.934 kB per alloc
Address space used: 8.000 kB
NJAMD Overhead at exit: 7.934 kB
Well, it's obvious that exit() clears all the memory allocated by an application. But if you run an application that should run for a long time, and start/stop threads, eventually your application will eat all the available memory.
I would like to free all the allocation memory during the work of my program, not after it ends.
what i am trying to say is memory is not being leaked as such...but maybe njamd is not being able to capture that piece of code and hence calls it a leak....if you see...try doing a malloc from a thread and free it...even then you'd see only one leak and two allocations.....if you are freeing all the memory that you have allocated..then you'd be fine...as you''ll see that 'your" threads arent leaking any memory...
i couild be wrong..but this is what i feel...it is just that the njamd might not be doing any check on the manager thread..and that is the memory i see getting "leaked"..it is the same amount of memory leaking no matter how many threads i run ...have you tried doing the same thing on 2.6 kernel? or on solaris perhaps...they dont have manager threads...maybe you'll get no leaks...
Thank you, I've checked, and it seems that only manager's memory leaks (because 68 leaked bytes don't depend on how many threads do I start).
Actually, I tested it on 2.6 kernel, but the kernel version alone isn't the case. I have old glibc without NPTL, so I get a manager thread and this leak.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.