none
recovering memory from managed dlls called from unmanaged application RRS feed

  • Question

  • We have a large windows application(unmanaged C++) that seems to be leaking memory.  It seems to occur after we have loaded/unloaded 3rd party COM objects that are written in managed .NET.  Using PerfMon we can see the private usage climbing, even though we have confirmed that the destructors of the COM objects have been called.  Is there a way to recover this memory?  I have tried writing a separate managed COM object that tries to call GC.Collect, but that does not seem to be helping.  I have tried wrapping the construction/destruction of the objects with _CrtMemCheckpoint and related calls, but the output is to large to decipher
    • Moved by Yi Feng Li Wednesday, December 15, 2010 3:39 AM GC question (From:Visual C++ General)
    Monday, December 13, 2010 6:42 PM

All replies

  • Hello AGrahamAtFES,

    Collecting GC doesn’t help on memory leak issue at most of time. This is because the memory is occupied by some object on heap. When .Net collects GC, it detects the reference of the memory block, the memory will not be released (collected) if it referenced by root and it will enter the next GC generation. Based on my knowledge, we should fix the memory leak from the code side.    

    Since you are using 3<sup>rd</sup> party COM object, if you are sure the problem comes from the COM component, we recommend you contact your vender company to debug the code and fix the problem.

    If I misunderstand you, please let me know.

    Regards,

    Yi Feng Li


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, December 14, 2010 8:36 AM
  • If we destroy the COM object and force the dll to be unloaded could the memory then be recovered?
    Tuesday, December 14, 2010 3:26 PM
  • Hi AGrahamAtFES,

     

    Since your question is much related to CLR GC collection, I’m moving this thread to Common Language Runtime forum for better support.

     

    Thank you for your understanding.

     

    Regards,

    Yi Feng Li


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, December 15, 2010 3:39 AM
  •  

    Hi AGrahamAtFES,

     

    The climbing of private usage is not always indicates a managed memory leak, you may undergoing an unmanaged memory leak, anyway, could you please following this article to find out the memory leak type?

     

    Detecting .NET Memory Leaks


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by eryang Wednesday, December 22, 2010 5:05 AM
    • Unmarked as answer by AGrahamAtFES Wednesday, December 22, 2010 3:45 PM
    Wednesday, December 15, 2010 3:42 AM
  • While following the steps in the given article my application is not listed under the .NET CLR Memory/Bytes in all heaps performance counter.

     

    -edit.. ok it did finally show up after I loaded the .NET ActiveX object.

    Wednesday, December 15, 2010 3:19 PM
  • I ca not get the debugdiag tool to correctly analyze the dump files that are created.  I have tried debugging the scripts and it is having issues because the heap sizes are 0 which is causing divide by 0 errors.  I stepped over all of those errors, but then the script hung while analyzing the leak section.
    Wednesday, December 15, 2010 6:30 PM
  • May I know whether it is a managed memory leak? what error messages does DebugDiag show?
    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, December 16, 2010 3:27 AM
  • We temporarily mark a reply since the thread idle for a long time, please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

     

    You may contact support at http://support.microsoft.com if the issue is urgent.

     

    Please feel freet to let us know if you have any concern.


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, December 22, 2010 5:03 AM
  • May I know whether it is a managed memory leak? what error messages does DebugDiag show?
    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, December 23, 2010 4:57 AM