Find the answer to your Linux question:
Results 1 to 4 of 4
I'm having trouble with a memory leak as a result of spawning threads. Each time I create a thread, approx. 10 megs of memory are acquired and never returned. The ...
  1. #1
    Just Joined!
    Join Date
    Feb 2008
    Posts
    2

    Spawning Threads Leaking Memory

    I'm having trouble with a memory leak as a result of spawning threads. Each time I create a thread, approx. 10 megs of memory are acquired and never returned. The thread is exiting, and the problem still happens if I gut the thread so that it does nothing (allocates nothing) but exit. Any ideas out there?

    Thanks,
    Bob

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Two questions:
    1. Threads are implemented in more than one way. Are we talking about POSIX threads (pthreads) here?
    2. When you gut each thread so it's empty, I know you're still losing memory, but is it still about 10 megs?
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    Just Joined!
    Join Date
    Feb 2008
    Posts
    2
    Hi,

    We're using the thread implementation from ACE 5.5 (in order to give our software platform indepedence). I'm not sure what underlying thread mechanism (POSIX Pthreads or other) it is using to create the thread on Linux.

    Yes, it still jumps by 10 megs even if the thread does absolutely nothing, but exit upon being spawned.

  4. #4
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    From splashing around on the web, I suspect that ACE uses POSIX threads. I'm not familiar with ACE.

    On the one hand, I suspect that POSIX threads are at least as portable as ACE, and even more so if you should find a platform for which C++ is not available. :)

    On the other hand, I'm guessing that you've already sunk enough work into using ACE that it would be a major headache to retool. Further, pthreads programming is not for the faint of heart, and it's easy to find yourself in a difficult-to-debug situation, and ACE may reduce the danger of that.

    I do know that if you write a bare-bones application using POSIX threads (but not using ACE or any other layer over those POSIX threads) which simply launches threads and joins them when they exit, you're not going to get any 10 MB of overhead per thread.

    So I guess my question is this:

    Did you get your code which does "absolutely nothing" by taking your application and either adding a snippet of code which exits each thread immediately, or deleting all code in the thread's major function?

    Or did you start from scratch to write such a bare-bones nonsense application, using (for example) no more code and no more global and local variables than absolutely necessary, and defining no unnecessary new classes?

    If you did the first of these, try the second. If the first one consumes 10 MB of memory and the second does not, that gives you a direction in which to look.

    Sorry I couldn't be of more help than this.
    --
    Bill

    Old age and treachery will overcome youth and skill.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...