none
How to diagnose and fix problem with memory leak? RRS feed

  • Question

  • I have some WinForms application.
    This application should be able to work for a long time (at least 2 days) without any problems.
    After one day of working I have memory leak, there is thrown OutOfMemoryException.

    How can I diagnose and fix this terrible problem? Are there any tools which can help me with this?
    Because I browsed my source code and I cannot find what can be reason of this problem.

    Regards.
    Monday, November 3, 2008 10:17 AM

Answers

  • Use a profiler.  I've heard good things about Red Gate's Ants, CLRProfiler is a freebie but awkward.
    Hans Passant.
    • Marked as answer by kicaj Thursday, November 6, 2008 7:22 AM
    Monday, November 3, 2008 10:21 AM
    Moderator
  • Been there, last week in fact...

    Sadly, the leak can be at 2 place: it can be either a managed memory leak or an unmanaged memory leak.

    THe first step is to investigate a managed memory leak. My personnal suggestion is to use scitech .Net memory profiler. (http://memprofiler.com) It is a great tool that allows you to compare snapshots of managed memory and navigate to the exact field that is still holding reference to your object. It is easy enough to use, yet very complete and thorough. They provide a free trial period, but I think you will realize it is well worth the investment.

    If the leak is in unmanaged memory (you do not see any buildup of references in the profiler) then I suggest that you disable block of your application to see if you can pinpoint the source of the leak. I have found one occurence of this kind of leak when I was using the wrong ADO .net API method to execute a query.

    Vincent
    • Marked as answer by kicaj Thursday, November 6, 2008 7:22 AM
    Wednesday, November 5, 2008 6:13 PM

All replies

  • Use a profiler.  I've heard good things about Red Gate's Ants, CLRProfiler is a freebie but awkward.
    Hans Passant.
    • Marked as answer by kicaj Thursday, November 6, 2008 7:22 AM
    Monday, November 3, 2008 10:21 AM
    Moderator
  • Been there, last week in fact...

    Sadly, the leak can be at 2 place: it can be either a managed memory leak or an unmanaged memory leak.

    THe first step is to investigate a managed memory leak. My personnal suggestion is to use scitech .Net memory profiler. (http://memprofiler.com) It is a great tool that allows you to compare snapshots of managed memory and navigate to the exact field that is still holding reference to your object. It is easy enough to use, yet very complete and thorough. They provide a free trial period, but I think you will realize it is well worth the investment.

    If the leak is in unmanaged memory (you do not see any buildup of references in the profiler) then I suggest that you disable block of your application to see if you can pinpoint the source of the leak. I have found one occurence of this kind of leak when I was using the wrong ADO .net API method to execute a query.

    Vincent
    • Marked as answer by kicaj Thursday, November 6, 2008 7:22 AM
    Wednesday, November 5, 2008 6:13 PM