ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » General IBM MQ Support » .NET MQ memory issue

Post new topic  Reply to topic
 .NET MQ memory issue « View previous topic :: View next topic » 
Author Message
angka
PostPosted: Wed Aug 01, 2007 11:20 pm    Post subject: .NET MQ memory issue Reply with quote

Chevalier

Joined: 20 Sep 2005
Posts: 406

Hi all,

I wrote a code for MQ Client using .net c# to poll a queue and wait for 10 secs and retry after 10 secs and I realise from the task manager that the memory keep increasing even when there is no message. below are my code please take a look.

After connecting to the QMgr and open the Queue...

Code:
 public partial class MQ_PRISMS : Form
    {
        MQ_API objMQ = new MQ_API();
        string strReturn = null;

     //Some other methods to connect and open Queue


        public void MQGetMessage()
        {
            while (true)
            {
                strReturn = objMQ.MQGetMessage();
               
                if (strReturn != "2033" & strReturn != "Message Committed")
                {
                   //do something
                }
                             
         }
        }
     }






class MQ_API
    {
        MQQueueManager queueManager;
        MQQueue queue;
        MQQueue queueException;
        MQMessage queueMessage;
        MQPutMessageOptions MQPutMsgOpt;
        MQGetMessageOptions MQGetMsgOpt;
        string strExceptionQueueName;
        string strReturn;
        string strMessage;
        Boolean blnSuccess = false;
        Boolean blnDBSuccess = false;
        Boolean blnConnectSuccess = false;
        Boolean blnOpenSuccess = false;
        int intGetMsgOptions;
        int intPutMsgOptions;
        string strApplDataID;

       
        public string MQGetMessage()
        {
            intGetMsgOptions = MQC.MQGMO_CONVERT | MQC.MQGMO_SYNCPOINT | MQC.MQGMO_WAIT;
            strExceptionQueueName = Properties.Settings.Default.ErrorQueueName;
             try
            {
                queueMessage = new MQMessage();
                queueMessage.CharacterSet = 437;
                queueMessage.Encoding = 546;
                MQGetMsgOpt = new MQGetMessageOptions();
                MQGetMsgOpt.Options = intGetMsgOptions;
                MQGetMsgOpt.WaitInterval = 10000;
                queue.Get(queueMessage, MQGetMsgOpt); //"jump to CATCH when no message in the queue.."
                strMessage = queueMessage.ReadString(queueMessage.MessageLength);
                strApplDataID = queueMessage.ApplicationIdData;
                strApplDataID = strApplDataID.Substring(0, 8);
                //Do some other stuff...
               
            }
            catch (MQException MQexp)
            {
                if (MQexp.ReasonCode == 2033)
                {
                    strReturn = Convert.ToString(MQexp.ReasonCode);
                }
                else
                    strReturn = "MQException: " + Convert.ToString(MQexp.ReasonCode);
            }
            catch (Exception exp)
            {
                strReturn = "Exception: " + exp.Message;
            }

            return strReturn;
        }
   }
}
Back to top
View user's profile Send private message
Vitor
PostPosted: Wed Aug 01, 2007 11:59 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

Which version of MQ & .NET are you using? I have a faint memory (!) of a memory leak in early versions of the .NET support.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
angka
PostPosted: Thu Aug 02, 2007 12:16 am    Post subject: Reply with quote

Chevalier

Joined: 20 Sep 2005
Posts: 406

Hi,

I am using MQ V6.000 and .net Framework V2.

thought the garbage collector should handle the new object?

Thanks.
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Aug 02, 2007 12:34 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

Ok, so not what I was thinking of clearly. But 2 other points occur:

1) You should apply some maintenance to MQ - the plain v6 is not all it could be;

2) You may want to consider using .NET 1.1 instead.

A lot of things should happen in this world. A surprising number of them don't, for one reason or another.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
angka
PostPosted: Thu Aug 02, 2007 12:57 am    Post subject: Reply with quote

Chevalier

Joined: 20 Sep 2005
Posts: 406

Hi,

for MQ client I am using the newest version available but MQ server only v6.0. i cant downgrade the .net version cos some other application using it.

but the code is quite simple.. the basic for MQ Client to get messages MQ from server. =(

thanks.
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Aug 02, 2007 1:01 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

angka wrote:

but the code is quite simple.. the basic for MQ Client to get messages MQ from server. =(


Indeed so.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
angka
PostPosted: Thu Aug 02, 2007 6:07 pm    Post subject: Reply with quote

Chevalier

Joined: 20 Sep 2005
Posts: 406

Hi,

Any coding suggestion what to do?

Thanks.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Thu Aug 02, 2007 9:04 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20697
Location: LI,NY

angka wrote:
Hi,

Any coding suggestion what to do?

Thanks.

Make sure you close correctly any MQ resource used after you are done with it. It is never a good thing to leave the resource for automatic garbage collection ... You should explicitely close(or release) the resource when no longer needed. This makes for better resource availability and memory management. Also use resource pools whenever available and appropriate.

Enjoy
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
angka
PostPosted: Fri Aug 03, 2007 1:04 am    Post subject: Reply with quote

Chevalier

Joined: 20 Sep 2005
Posts: 406

Hi,

But MQmessage for .net can't release the object. it doesnt have any method to release. I believe i kept new the MQmessage object and tt why the memory increase over time. GC will only collect it when it gets to a value.

Thanks
Back to top
View user's profile Send private message
kevinf2349
PostPosted: Fri Aug 03, 2007 4:51 am    Post subject: Reply with quote

Grand Master

Joined: 28 Feb 2003
Posts: 1311
Location: USA

Why are you 'polling' the queue in the first place?

Why not just issue a get with an unlimitied wait?
Back to top
View user's profile Send private message
angka
PostPosted: Sun Aug 05, 2007 5:53 pm    Post subject: Reply with quote

Chevalier

Joined: 20 Sep 2005
Posts: 406

Hi,

I did a get with unlimited wait too, the memory increase but slower only. as long as there is a message the memory increase.. i left it over the weekend with no message sent the memory stays. I think shld be the GC not doing the work as expected.

I tried out on the debugger mode using VS.net, the MQ message object i created around 20 instances ago willl only be release then. this maybe due to debugger mode but i believe the release may take a while to release the object too.

I tried sending messages at 10 per sec, the memory increase like mad.. it gets over 500 mb in around 30 mins...
Back to top
View user's profile Send private message
kevinf2349
PostPosted: Sun Aug 05, 2007 7:48 pm    Post subject: Reply with quote

Grand Master

Joined: 28 Feb 2003
Posts: 1311
Location: USA

Have you tried disposing of the message area within the same loop that you create the new message area?
Back to top
View user's profile Send private message
angka
PostPosted: Sun Aug 05, 2007 8:59 pm    Post subject: Reply with quote

Chevalier

Joined: 20 Sep 2005
Posts: 406

What you mean by disposing? MQMessage does not have tt method dispose.

Thanks
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » General IBM MQ Support » .NET MQ memory issue
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.