Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Memory Leakage with Message Queue in .Net ??

588 views
Skip to first unread message

Carsten Geuer

unread,
Feb 11, 2007, 7:54:00 PM2/11/07
to
Hi there, we have a service wihich sends and receives Messages from
MessageQueue at least 5 times every second. Unfortunately the memory usage of
this services increase without limit.

Yes, I dispose every Message after sending. And in case I create a new
MessageQueue instance I dispose it as well.

I know that the Garbage Collector is sometimes a little bit lazy, but even
after three hours the memory usage still increase (it has now reached 200MB).

Any ideas ?

Carsten



EmeraldShield

unread,
Feb 12, 2007, 5:27:49 PM2/12/07
to

"Carsten Geuer" <Carste...@discussions.microsoft.com> wrote in message
news:AFF664ED-9710-4F09...@microsoft.com...

That your app is leaking memory. That is my idea.

Without some concrete example of WHY you think it is leaking... Um, no. I
have used it for over three months continuos running and no memory leaks.
So it is in your app.

Get a good memory profiler like Red Gate and see what objects are being left
laying around.

Carsten Geuer

unread,
Feb 12, 2007, 11:08:01 PM2/12/07
to
Hi EmeraldShield,

its the XmlMessageFormatter which caused the problem. When I move to
BinaryMessageFormatter the problem disappears. I only use one
XmlMessageFormatter for the whole application (so not always create a new
XmlMessageFormatter). It might be the the problem is fixed in DotNet 2.0, but
for this application we still have to use 1.1.

By the way, its not so easy to produce a memory leakage in .Net. You have to
fill lists without limits or do not dispose "external" resources. So it was
pretty obvious that the problem came from MessageQueue (which I like very
much!).

Carsten

Frank Boyne

unread,
Feb 14, 2007, 6:06:28 PM2/14/07
to
"Carsten Geuer" <Carste...@discussions.microsoft.com> wrote in
message news:AFF664ED-9710-4F09...@microsoft.com...
> Unfortunately the memory usage of
> this services increase without limit.

It is possible that this is just standard MSMQ behaviour, it may be that
you just haven't reached the limit yet.

> I know that the Garbage Collector is sometimes a little bit lazy, but
> even
> after three hours the memory usage still increase (it has now reached
> 200MB).

Yes but MSMQ's own "garbage collector" is even lazier. MSMQ works by
storing the contents of messages in memory mapped files. When a message
is withdrawn from a queue, the memory occupied by the now discarded
message is marked as no longer in-use but that's all. When all the
messages in an individual memory mapped file have been marked as no
longer in-use, that file is empty and so is a candidate to be cleaned
up.

The default clean-up interval is six hours (I told you it was lazy!)
You can change the default interval by changing the
MessageCleanupInterval registry key and then restarting the MSMQ
service. http://support.microsoft.com/kb/199312/en-us

One quick way to discover if this is your problem is to write a small
program to call MQMgmtAction with your machine name, a "MACHINE" object
name and a "TIDY" action. That will force MSMQ to run the clean-up
right there and then. An even quicker solution is to run a VBScript (or
a script in the language of your choice) to call MSMQApplication.Tidy
http://msdn2.microsoft.com/en-us/library/ms700377.aspx

If you get your memory back, then you know you just need to tidy up more
frequently.

Note however that clean-up only deals with empty files. Thus one
message sitting in a queue somewhere can keep an entire file from being
cleaned up. That means that one message, perhaps only one byte in
length can effectively hold up to 4 MB of memory in use (4 MB being the
upper limit on the size of a memory mapped file).

Nonetheless, there are some leaks in MSMQ. Try searcing for 'leak' in
the Knowledge Base here:
http://support.microsoft.com/search/?adv=1&spid=860. You should get 10
KB articles (some of which only apply to MSMQ 1.0


John Breakwell (MSFT)

unread,
Feb 15, 2007, 6:19:16 AM2/15/07
to
What Frank says is excellent stuff but I think the memory profile that
Carsten mentions may not match the 6-hour garbage collection pattern.

For example, say you have a single spike of 100MB of messages arriving in 5
minutes and these messages are quickly consumed.
As Frank says, you will have 100MB of empty memory-mapped files.
New messages, though, will re-use the empty files so the memory usage will
not rise above 100MB and after six hours will drop to whatever is needed by
the existing volume of messages.

I would use Performance Monitor to check what MSMQ thinks is in memory.
Is "Message Queue/Total bytes in all queues" anywhere near the amount of
leaked memory?

You can also get a diectory listing of the MSMQ\Storage directory and see if
there is a corresponding volume taken up there.

Cheers
John Breakwell

"Frank Boyne" <frank...@unisys.com> wrote in message
news:erGTDzIU...@TK2MSFTNGP02.phx.gbl...

0 new messages