none
InvokeMember memory leaks RRS feed

  • Question

  • I have discovered memory leaks in a legacy code that I maintain.

    Here they are:

    FR_Type.InvokeMember("GetStatus", System.Reflection.BindingFlags.InvokeMethod, null, FR_Object, null);
    Result = FR_Type.InvokeMember("CheckState", System.Reflection.BindingFlags.GetProperty, null, FR_Object, null);

    These code lines are responsible for communication with printer. FR_Type and FR_Object are instance fields.

    How can I fix this problem?


    Monday, July 30, 2012 12:01 PM

Answers

  • Hi FofanovIs,

    Welcome to the MSDN Forum.

    The "memory used" is managed memory, right?

    If so, you are not expected the memory usage down as soon as the loop ends, the GC manages the managed resource: http://msdn.microsoft.com/en-us/magazine/bb985010.aspx

    Garbage collection in the Microsoft .NET common language runtime environment completely absolves the developer from tracking memory usage and knowing when to free memory.

    So this may not be a memory leak. To identfy this, please refer to this KB: http://support.microsoft.com/kb/318263 

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, July 31, 2012 1:10 PM
    Moderator

All replies

  • You'll have to examine (or share with us) the code for GetStatus and CheckState.  Those calls themselves don't leak anything.
    Monday, July 30, 2012 12:46 PM
  • And what if GetStatus and CheckState are the functions of a driver shiped by the third party?
    Monday, July 30, 2012 1:23 PM
  • Well, how do you know you have a memory leak?  Are you using the CLRProfiler?  What object is leaking?  Are you leaking managed or unmanaged memory?  Or are you leaking non-paged pool memory in a driver or something crazy like that?  Describe more details about what you know about the leak.  Describe how you diagnosed the leak and how you are observing it.  These will be clues about how to fix it.
    Monday, July 30, 2012 4:47 PM
  • I observe increasing "memory used" by the process in the task manager when this function is being called many times in a for loop. When the loop is ended the memory consume stays at the same high level.
    Tuesday, July 31, 2012 10:30 AM
  • Hi FofanovIs,

    Welcome to the MSDN Forum.

    The "memory used" is managed memory, right?

    If so, you are not expected the memory usage down as soon as the loop ends, the GC manages the managed resource: http://msdn.microsoft.com/en-us/magazine/bb985010.aspx

    Garbage collection in the Microsoft .NET common language runtime environment completely absolves the developer from tracking memory usage and knowing when to free memory.

    So this may not be a memory leak. To identfy this, please refer to this KB: http://support.microsoft.com/kb/318263 

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, July 31, 2012 1:10 PM
    Moderator
  • Does the GetStatus return something? What type is it? 

    What type does CheckState return?

    Tuesday, July 31, 2012 2:14 PM
    Moderator
  • You should consider trying out the CLRProfiler to diagnose your leak.
    Tuesday, July 31, 2012 6:38 PM