none
Free lost unmanaged memory RRS feed

  • Question

  • Hi all,

    I've using a 3rd party C++ DLL.  The DLL is leaking memory.  I'm calling that DLL functios from a VS 2005 C# program.
    I need to use that DLL before the memory leaking would be fixed.
    Is there a way (even a brutal way) to release that "lost" memory from the program?
    Wednesday, January 13, 2010 3:47 PM

Answers

  • There is one complex way: create an executable wrapper for the dll, which exposes the dll functions as an IPC API.

    Then shutdown and restart the application when you need to claim the memory.

    I had to do this once in a production system (the database driver dll would crash if there were network errors). It wasn't pretty, but it worked.

           -Steve
    Programming blog: http://nitoprograms.blogspot.com/
      Including my TCP/IP .NET Sockets FAQ

    Microsoft Certified Professional Developer
    Wednesday, January 13, 2010 3:58 PM
  • Like I said in my previous post:
    - Create a wrapper executable that exposes the DLL functions using IPC, like WCF or .NET remoting.
    - Insert logic in your main exe that starts and starts the wrapper exe as necessary.

           -Steve
    Programming blog: http://nitoprograms.blogspot.com/
      Including my TCP/IP .NET Sockets FAQ

    Microsoft Certified Professional Developer
    • Marked as answer by eryang Friday, January 22, 2010 5:41 AM
    Wednesday, January 13, 2010 4:10 PM

All replies

  • Nope, if they lost the pointer you can no longer free the memory.
    Wednesday, January 13, 2010 3:51 PM
  • Thanks for the quick reply Ray M,

    Will the lost  unmanaged memory be released when the C# program terminates?
    Wednesday, January 13, 2010 3:57 PM
  • There is one complex way: create an executable wrapper for the dll, which exposes the dll functions as an IPC API.

    Then shutdown and restart the application when you need to claim the memory.

    I had to do this once in a production system (the database driver dll would crash if there were network errors). It wasn't pretty, but it worked.

           -Steve
    Programming blog: http://nitoprograms.blogspot.com/
      Including my TCP/IP .NET Sockets FAQ

    Microsoft Certified Professional Developer
    Wednesday, January 13, 2010 3:58 PM
  • Thanks for the quick reply Ray M,

    Will the lost  unmanaged memory be released when the C# program terminates?

    Yes, all memory is freed once a process terminates.
    Wednesday, January 13, 2010 4:03 PM
  • Thanks Steve,

    Can you reffer me to some example of such a solution or give me the basic guidelines of such an implementation?

      AssafT

    Wednesday, January 13, 2010 4:06 PM
  • Like I said in my previous post:
    - Create a wrapper executable that exposes the DLL functions using IPC, like WCF or .NET remoting.
    - Insert logic in your main exe that starts and starts the wrapper exe as necessary.

           -Steve
    Programming blog: http://nitoprograms.blogspot.com/
      Including my TCP/IP .NET Sockets FAQ

    Microsoft Certified Professional Developer
    • Marked as answer by eryang Friday, January 22, 2010 5:41 AM
    Wednesday, January 13, 2010 4:10 PM