Finding a resource leak, is it the background thread or somethingelse?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Cartoper

    Finding a resource leak, is it the background thread or somethingelse?

    My application appears to have a recourse leak. When the user starts
    a background process, the handle count in Process Explorer (PE) goes
    up by about 10, sometime 1 or 2 more, sometimes 1 or 2 less. When the
    task is completed, there are somewhere between 4 and 7 handles still
    open.

    My process is loading images and shrinking them down. I went through
    all the code and found some objects that implement the IDisposable
    interface which I was not calling Dispose or Close on. Objects such
    as AutoResetEvent, Graphic, and Image. I have either encapsulated
    them in a using clause or called Dispose on the object before setting
    to null and it seems to have no effect.

    So I am now wondering where might I find this leak? In the unmanaged
    thread handles need to be closed when no longer needed. I am not
    seeing any way of cleaning up a managed thread, once it is completed.
    Is there some cleanup procedure I am missing or are there other
    objects out there that I am not cleaning up correctly?

    Are there any good tools out there that might help me in finding this
    resource leak?

    Cartoper
  • Willy Denoyette [MVP]

    #2
    Re: Finding a resource leak, is it the background thread or something else?

    "Cartoper" <cartoper@gmail .comwrote in message
    news:f63418d9-54d3-413a-810f-9ab69d0fa1f1@u7 2g2000hsf.googl egroups.com...
    My application appears to have a recourse leak. When the user starts
    a background process, the handle count in Process Explorer (PE) goes
    up by about 10, sometime 1 or 2 more, sometimes 1 or 2 less. When the
    task is completed, there are somewhere between 4 and 7 handles still
    open.
    >
    My process is loading images and shrinking them down. I went through
    all the code and found some objects that implement the IDisposable
    interface which I was not calling Dispose or Close on. Objects such
    as AutoResetEvent, Graphic, and Image. I have either encapsulated
    them in a using clause or called Dispose on the object before setting
    to null and it seems to have no effect.
    >
    So I am now wondering where might I find this leak? In the unmanaged
    thread handles need to be closed when no longer needed. I am not
    seeing any way of cleaning up a managed thread, once it is completed.
    Is there some cleanup procedure I am missing or are there other
    objects out there that I am not cleaning up correctly?
    >
    Are there any good tools out there that might help me in finding this
    resource leak?
    >
    Cartoper


    Using Process Explorer you can get a list of the OS handles owned by the
    process, so it's not that hard to see whether the "leaked" handles are the
    thread handles. My guess is that they are no thread handles, but event
    handles.

    Willy.

    Comment

    • Cartoper

      #3
      Re: Finding a resource leak, is it the background thread or somethingelse?

      On Mar 19, 6:21 am, "Willy Denoyette [MVP]"
      <willy.denoye.. .@telenet.bewro te:
      This doesn't mean you are leaking handles, an handle leak would mean that
      the handle count keeps increasing without ever going down during the
      lifetime of the process, this is not what's happening here I guess, please
      correct me if I'm wrong.
      Please forgive me, but I thought I cleared stated that BEFORE starting
      the thread the handle count was say 309, AFTER the thread starts the
      count is above 313, once it stops and time goes by, the handle count
      stays at 313. The handle count NEVER EVER returns to 309 once the
      thread is started, absolutely NEVER returns. The next time the the
      thread is started the count rises above 317 and settles at 317 once
      the thread has exited, again NEVER EVER to return to 313 or 309. I am
      pretty darn sure this would be considered a handle leak. If it isn't
      I most definitly need to find another way to makine a living (like
      writing code in good old unmanaged C++).
      Also don't forget that the CLR creates it's own OS
      objects, the CLR is responsible to release these handles, also don't call
      GC.Collect without having a serious reason to do so.
      The GC.Collect was for DEBUGGING purposes ONLY. It is quite clearn
      that the OS is creating these handles, the only question is, am I not
      doing something that will make then get cleaned up?

      Cartoper

      Comment

      • Cartoper

        #4
        Re: Finding a resource leak, is it the background thread or somethingelse?

        On Mar 20, 8:24 am, "Willy Denoyette [MVP]"
        <willy.denoye.. .@telenet.bewro te:
        ***
        Not in the menus, but on the tool bar, the sixth button is a toggle - View
        Dll's/View Handles. You can also toggle using Cntrl+H/Cntrl/D
        ***
        Sweat, that will hopefully make ALL the difference! I will let you
        know.

        Cartoper

        Comment

        Working...