MQ memory leak

J

José Joye

Hi,

I have implemented a Service that is responsible for getting messages from a
MS MQ located on a remote machine. I'm getting memory leak from time to time
(???). In some situation, it is easier to reproduce (e.g.: remote machine
not available). After about 1 day, I get a usage of 300MB of memory.
I have used .NET Memory Profiler tool to try to see where the leak is
located. For all the leaky instances, I can see the following (I should say
that is not too clear what it is trying to show...):

Message..ctor(MessagePropertyFilter)
MessageQueue.ReceiveCurrent(TimeSpan, int, IntPTR, MessagePropertyFilter,
......)
MessageQueue.Receive(TimeSpan)
MQEvlReceiver.Receive(int) <--------My appl.
MQReception.DoWork() <--------My appl.

I have check and re-check my code, I cannot see any problem with it.

Does anyone knows about a leak with MQ in a similar case?

Here is my config:
W2K sp3 english
..NET 1.1

Thanks,
José
 
N

Nicholas Paldino [.NET/C# MVP]

Jose,

Are you calling Dispose on all of the classes that you are using? For
example, are you calling Dispose on the MessageQueue instance you are using?
This could be a major source of any leaks you might be seeing.

Hope this helps.
 
J

José Joye

In fact, before entering my loop, I create an instance of a class that will
try to fetch messages. This class has a private member :
private MessageQueue m_mq;

Within the method called by the main loop, whenever I try to fetch a
message, I use m_mq.Receive(TimeToWait).
In case a message is retrieved, I pass it back to my main loop. In any other
situation, I return a null.

There is a situation where I call Dispose() method on my "m_mq" member. This
is when I get an error of type MessageQueueErrorCode.QueueNotAvailable. In
such a case, I apply the following algorithm:
m_mq.Dispose();
m_mq=null;
MessageQueue.ClearConnectionCache();
m_mq = new MessageQueue(m_strQueueName);
MessageQueue.EnableConnection = true;


When the main loop receive the answer (either a message or a null), it will
process the message and call the method again to get the next message.

In that sense, I think I did not forgot to call any Dispose().

José

Nicholas Paldino said:
Jose,

Are you calling Dispose on all of the classes that you are using? For
example, are you calling Dispose on the MessageQueue instance you are using?
This could be a major source of any leaks you might be seeing.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

José Joye said:
Hi,

I have implemented a Service that is responsible for getting messages
from
a
MS MQ located on a remote machine. I'm getting memory leak from time to time
(???). In some situation, it is easier to reproduce (e.g.: remote machine
not available). After about 1 day, I get a usage of 300MB of memory.
I have used .NET Memory Profiler tool to try to see where the leak is
located. For all the leaky instances, I can see the following (I should say
that is not too clear what it is trying to show...):

Message..ctor(MessagePropertyFilter)
MessageQueue.ReceiveCurrent(TimeSpan, int, IntPTR, MessagePropertyFilter,
.....)
MessageQueue.Receive(TimeSpan)
MQEvlReceiver.Receive(int) <--------My appl.
MQReception.DoWork() <--------My appl.

I have check and re-check my code, I cannot see any problem with it.

Does anyone knows about a leak with MQ in a similar case?

Here is my config:
W2K sp3 english
.NET 1.1

Thanks,
José
 
M

Muscha

Are you calling Dispose on all of the classes that you are using? For
example, are you calling Dispose on the MessageQueue instance you are using?
This could be a major source of any leaks you might be seeing.

Why should we call Dispose() manually? Shouldn't be calling Close() is
enough? I thought dispose will be called when the object is about to be
garbage collected and shouldn't be called manualy.

/m
Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

José Joye said:
Hi,

I have implemented a Service that is responsible for getting messages
from
a
MS MQ located on a remote machine. I'm getting memory leak from time to time
(???). In some situation, it is easier to reproduce (e.g.: remote machine
not available). After about 1 day, I get a usage of 300MB of memory.
I have used .NET Memory Profiler tool to try to see where the leak is
located. For all the leaky instances, I can see the following (I should say
that is not too clear what it is trying to show...):

Message..ctor(MessagePropertyFilter)
MessageQueue.ReceiveCurrent(TimeSpan, int, IntPTR, MessagePropertyFilter,
.....)
MessageQueue.Receive(TimeSpan)
MQEvlReceiver.Receive(int) <--------My appl.
MQReception.DoWork() <--------My appl.

I have check and re-check my code, I cannot see any problem with it.

Does anyone knows about a leak with MQ in a similar case?

Here is my config:
W2K sp3 english
.NET 1.1

Thanks,
José
 
N

Nicholas Paldino [.NET/C# MVP]

Muscha,

They are doing the same thing. For some classes though, it fits better
to have a method named "Close" as opposed to "Dispose" when dealing with the
resource (for example, on a FileStream, if you Dispose it, it might indicate
you are getting rid of the file, as opposed to closing it).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Muscha said:
Are you calling Dispose on all of the classes that you are using? For
example, are you calling Dispose on the MessageQueue instance you are using?
This could be a major source of any leaks you might be seeing.

Why should we call Dispose() manually? Shouldn't be calling Close() is
enough? I thought dispose will be called when the object is about to be
garbage collected and shouldn't be called manualy.

/m
Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

José Joye said:
Hi,

I have implemented a Service that is responsible for getting messages
from
a
MS MQ located on a remote machine. I'm getting memory leak from time
to
time
(???). In some situation, it is easier to reproduce (e.g.: remote machine
not available). After about 1 day, I get a usage of 300MB of memory.
I have used .NET Memory Profiler tool to try to see where the leak is
located. For all the leaky instances, I can see the following (I
should
say
that is not too clear what it is trying to show...):

Message..ctor(MessagePropertyFilter)
MessageQueue.ReceiveCurrent(TimeSpan, int, IntPTR, MessagePropertyFilter,
.....)
MessageQueue.Receive(TimeSpan)
MQEvlReceiver.Receive(int) <--------My appl.
MQReception.DoWork() <--------My appl.

I have check and re-check my code, I cannot see any problem with it.

Does anyone knows about a leak with MQ in a similar case?

Here is my config:
W2K sp3 english
.NET 1.1

Thanks,
José
 
D

Doron Juster [MSFT]

Are you receiving from a remote computer ?
If yes, does the leak happen when remote is not available ?

Thanks, Doron
 
J

José Joye

Any news?

By the way, I have posted a detail about what I do just above in the same
thread.

José
 
J

jeff

Hi, it is very similar to the case what we have run to. One question, does
your Service open database connection and access database? It seems not
related to the memory leak, but we found it is.

-jeff
 
J

José Joye

Thanks,

However, the problem I face occurs only when the machine where the queue is
not located is not reachable.
Otherwise, I do not see any leak.
In my context, the queue is located on the machine writter and the reader
needs to remotly access it.

The machine where the reader is located is a production server where no dB
is installed.

José
 
J

jeff

Hi, Jose,

Since we were investigating our MSMQ memory leak problem these days. We have
a simple test program to repeat our problem. I modified the test program to
simulate your situation, and we also use Memory Profiler to monitor the
memory.

Test program runs on one machine, and the public queue is on another
machine. At beginning, Test program can send and read messages just fine. No
memory leak as you said. Then I unpluged the network cable of the test
program machine, make the public queue mahcine unreachable, and the Test
program got "Error occurs when reading from a queue on a remote computer"
error. But still, I didn't see any memory leak, and GC worked just fine.
So, if you have a small test program which can repeat your problem, that
could be little easier to figure it out.

good luck,

-jeff
 
J

José Joye

Hello again,

I think you are right, I have to make a small program to prove what I said.
The only problem is that I'm currently under stress regarding the project. I
will do it at a later stage.

José
 
J

José Joye

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top