none
High use of memory in an app that uses MSMQ RRS feed

  • Question

  • Hello,

    I've got the following problem.

    I've got an .NET application that's used to execute COM+ components asynchronously. This app receives an request to execute some component through a MSMQ queue.

    When it receives this request, it puts another message on another MSMQ queue to control the request's status. Then it execute this component, and update the request's status. After an hour, this messge is removed from MSMQ queue.

    But the memory used by the application grows gradually.

    I've taken a dump of it to analyse using WinDbg, and looking at the objects in memory (using !dumpheap -stat), I've found a huge number of System.Byte[], System.Object[] and System.Int32[]. But most intersting, a lots of System.Messaging.Message.

    It looks like those object aren't removed from memory. In code, every time the app loops through MSMQ messages using System.Messaging.MessageEnumerator, I make sure to call Dispose method for each Message.

    In my analysis, I used !gcroot to look where some instances of System.Messaging.Message are bound, but most of these objects doesn't have any link to others.

    I think the arrays that consumes so much memory are related to this high number of System.Messaging.* objects...

    Is there any memory leak with System.Messaging.* objects? Can anyone help to find how to clear those objects from memory?

    Thanks

    Top objects in memory:

    0x79bab994        868        45,136 System.Collections.Hashtable
    0x0a4f66b0        372        47,616 System.Data.DataColumn
    0x0078236c        178        57,968 System.Char[]
    0x00785bc4         62        64,232 System.DateTime[]
    0x03cd2a4c         18        65,016 Symantec.APM.I4DotNet.Collector.Tracker.EventTracker/InvocationFrame[]
    0x00782970        922       178,056 System.Collections.Hashtable/bucket[]
    0x79b94690      9,244     2,883,436 System.String
    0x001556f8        148     3,474,504      Free
    0x79bc183c    380,057     4,560,684 System.Int16
    0x03cd7ca4    380,286     4,563,432 System.Messaging.BinaryMessageFormatter
    0x79b9f4a0    760,116     9,121,392 System.Byte
    0x03cd9a50    380,286     9,126,864 System.Messaging.Interop.MessagePropertyVariants/MQPROPS
    0x79bd1e2c    380,291    15,211,640 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
    0x03cd98cc    380,286    22,817,160 System.Messaging.Interop.MessagePropertyVariants
    0x03cd9494    380,286    24,338,304 System.Messaging.Message
    0x79baafd0  2,281,482    27,377,784 System.Int32
    0x0078563c    380,286    45,634,320 System.Int16[]
    0x007826b0  1,141,753   141,548,648 System.Int32[]
    0x0078209c    763,015   173,636,804 System.Object[]
    0x00782c3c  1,905,141 1,012,925,024 System.Byte[]
    Total 9,552,043 objects, Total size: 1,498,711,528

    Fragmented blocks larger than 0.5MB:
          Addr     Size Followed by
    0x69edc58c 0.9MB large free object followed by 0x69fc32b8 System.Messaging.Message

    Friday, January 16, 2009 1:23 PM

Answers

All replies


  • You can try change the thread model from STA to MTA. In the beginning of the code, change the  [STAThread] to [MTAThread].



    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Thursday, January 22, 2009 10:22 AM
  • Zhi-Xin Ye, first I'm sorry about giving you feedback after so long time you had replied my question.

    I've just implemented the MTAThread thread model in my code, and its running in the production environment. We'll let it runs a couple of days, to analyse if this change has made some difference.
    Any news I'll tell you here.

    Thanks
    Monday, April 27, 2009 7:43 PM
  • Well, the changes didn't take any effect. The weird thing is that the same code is running in others servers without any memory issue, so we convinced the area responsible for the servers to format the server and reinstall Windows 2003.

    That's not the solution I'm looking for, but if it works, it's all right.

    Thanks.
    Tuesday, May 19, 2009 12:24 AM
  • Hi Fabio,

    See if this helps you:

    How To Optimize MSMQ Performance

    http://support.microsoft.com/kb/199428

    Regards,
    Jai
    Tuesday, October 20, 2009 4:20 PM