locked
IDispatchMessageInspector does not release resources RRS feed

  • Question

  • I am using IDispatchMessageInspector to monitor a number of webservices. It seems as though the IDispatchMessageInspector is not releasing disposing the requests and replies once it has completed logging them.

    Because of this problem it impacting greatly on the performance of the server because it not releasing the memory.

    I have tried using Request.close and Reply.Close but that doesn't work either.

    Any help would be greatly appreciated

    thanks


    Monday, March 26, 2012 8:38 AM

Answers

  • K, not enough code to give any valuable feedback, but:

    • Where are you getting the DbContext from for Entity Framework? Are you creating a new context for every message or are you re-using context? I ask this because DbContext keeps track of all items added to it and will thus keep them in memory unless cleared or reset or disposed.
    • I don't see any using or finally blocks in your code. You say you are disposing the response and request, but your code doesn't show it. Same applies to your DbContext in case you're creating a new one from scratch for every message.

    Have you tried running the code with the Profiler attached to see which object types are taking the memory and where their references are coming from?


    My blog: blog.jessehouwing.nl


    • Proposed as answer by servy42 Tuesday, March 27, 2012 2:28 PM
    • Edited by Jesse HouwingMVP Tuesday, March 27, 2012 3:34 PM
    • Marked as answer by Yugan Thursday, March 29, 2012 10:40 AM
    Tuesday, March 27, 2012 2:12 PM

All replies

  • Yugan,

    You say it is not releasing the memory, then the result will be that your server goes down. Is that the case or do you have the idea by for instance looking to the end user tool Taskmanager that the memory is not released, be aware Taskmanager is not all the time taking the processor to update it. It would mean a huge slowdown if that would happen?


    Success
    Cor

    Monday, March 26, 2012 9:23 AM
  • Hi Cor

    Currently the client and server is one server machine because the project is still in testing phase and I can see the the memory usage on the machine keeps going up each time a service request is logged.

    I am pretty sure that the problem lies on the server side because this only happens when i start logging requests from the webservices.

    you are right about the huge slowdown the machine slows down after a few hours

     
    • Edited by Yugan Monday, March 26, 2012 9:38 AM
    Monday, March 26, 2012 9:36 AM
  • Can you share some of the code so we might understand why the memory is not freed? Calling Dispose on the Request and Reply should clean up those, but there might be other issues at hand that cause these resources, or others, to remain opened.

    My blog: blog.jessehouwing.nl

    Monday, March 26, 2012 5:04 PM
  • public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel, InstanceContext instanceContext) { try { insert request into xml document..... Insert body of xmldoc to database via entity framework.......

    } catch (Exception ex) { save exception to database..... }

      return null; }

       void IDispatchMessageInspector.BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState)

            {
                try
                {

    insert reply into xml document...... Insert body of xmldoc to database via entity framework.......

    }

                

     }
          catch
            {
            }
            }




    • Edited by Yugan Tuesday, March 27, 2012 1:47 PM
    Tuesday, March 27, 2012 12:44 PM
  • K, not enough code to give any valuable feedback, but:

    • Where are you getting the DbContext from for Entity Framework? Are you creating a new context for every message or are you re-using context? I ask this because DbContext keeps track of all items added to it and will thus keep them in memory unless cleared or reset or disposed.
    • I don't see any using or finally blocks in your code. You say you are disposing the response and request, but your code doesn't show it. Same applies to your DbContext in case you're creating a new one from scratch for every message.

    Have you tried running the code with the Profiler attached to see which object types are taking the memory and where their references are coming from?


    My blog: blog.jessehouwing.nl


    • Proposed as answer by servy42 Tuesday, March 27, 2012 2:28 PM
    • Edited by Jesse HouwingMVP Tuesday, March 27, 2012 3:34 PM
    • Marked as answer by Yugan Thursday, March 29, 2012 10:40 AM
    Tuesday, March 27, 2012 2:12 PM
  • i found the problem.

    the objects referencing the db models were not getting disposed....


    Thursday, March 29, 2012 10:37 AM