Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to check individual threads for memory leaks

How to check individual threads for memory leaks

Scheduled Pinned Locked Moved C / C++ / MFC
performancetutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dave Midgley
    wrote on last edited by
    #1

    My work often involves writing multi-threaded turnkey systems - ie. programs which are designed to run "for ever". As such the kind of memory leaks that are found by BoundsChecker - memory that is allocated but not released when the program terminates - are relatively unimportant. What does cause problems is when a thread, running as a continuous loop, allocates memory each time round the loop that it doesn't free. Over time the system floods until eventually a catastrophic failure occurs. I need a way to monitor the heap usage of each individual thread, and detect whether it is leaking each time it executes its loop. (I know there is something called "thread-local storage" but I haven't been able to find much detail on it). If anyone knows any techniques for this, or can point me at some good articles or books, I'd be most grateful. Dave

    N J 2 Replies Last reply
    0
    • D Dave Midgley

      My work often involves writing multi-threaded turnkey systems - ie. programs which are designed to run "for ever". As such the kind of memory leaks that are found by BoundsChecker - memory that is allocated but not released when the program terminates - are relatively unimportant. What does cause problems is when a thread, running as a continuous loop, allocates memory each time round the loop that it doesn't free. Over time the system floods until eventually a catastrophic failure occurs. I need a way to monitor the heap usage of each individual thread, and detect whether it is leaking each time it executes its loop. (I know there is something called "thread-local storage" but I haven't been able to find much detail on it). If anyone knows any techniques for this, or can point me at some good articles or books, I'd be most grateful. Dave

      N Offline
      N Offline
      Niklas L
      wrote on last edited by
      #2

      I had the same problems a year back and ended up writing a sort of collector where I registered all dynamically allocated objects (and general storage) an unregistered them on deletion. The collector was instanciated on the stack for each thread. When the thread exited, the collector printed information about all objects still not unregistered. If there is a better way to do this, I also would like to know.

      1 Reply Last reply
      0
      • D Dave Midgley

        My work often involves writing multi-threaded turnkey systems - ie. programs which are designed to run "for ever". As such the kind of memory leaks that are found by BoundsChecker - memory that is allocated but not released when the program terminates - are relatively unimportant. What does cause problems is when a thread, running as a continuous loop, allocates memory each time round the loop that it doesn't free. Over time the system floods until eventually a catastrophic failure occurs. I need a way to monitor the heap usage of each individual thread, and detect whether it is leaking each time it executes its loop. (I know there is something called "thread-local storage" but I haven't been able to find much detail on it). If anyone knows any techniques for this, or can point me at some good articles or books, I'd be most grateful. Dave

        J Offline
        J Offline
        Joao Vaz
        wrote on last edited by
        #3

        As the name implies TLS is synonym of thread specific data. Use TlsAlloc on process/dll initialization, this will allocate a TLS index, then for each thread that needs specific instance data allocate some storage and pass the pointer to TlsSetValue, associating the TLS index with it. When a thread needs to get the instance value use TlsGetValue. Finally when all your threads are over, use TlsFree to release the Tls Index. The nº of TLS index is limited by process to 64 on 95 ??? , 64 or 80 in 98/me and 10?? in XP, please check msdn for the correct value, I don't remember clearly You could circumvent this if you wish by providing a pointer to a list/map of pseudo TLS indexes. Joao Vaz Unhappy TCL programmer

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups