MSXML, C# and huge memory leak

MSXML, C# and huge memory leak

Post by Gunnar Einarsso » Fri, 03 May 2002 21:39:06



Hi

I'm translateing a xml message and have to do it a lot.

We use MSXML ver. 4 and we have notice a huge memory leak in our program. We
have isolate the leak to one function.  We have removed everything but 2
lines, se below. Is is possible that the dotNet environment dose not free
the memory.

public void TranslateXML( string strMsg )
{
    DOMDocument oDoc = new DOMDocumentClass( );

    oDoc = null;

Quote:}

 
 
 

MSXML, C# and huge memory leak

Post by Gunnar Einarsso » Fri, 03 May 2002 22:16:18


We found the problem...

We have to call the release our self
System.Runtime.InteropServices.Marshal.ReleasecomObject( oDoc );


Quote:> Hi

> I'm translateing a xml message and have to do it a lot.

> We use MSXML ver. 4 and we have notice a huge memory leak in our program.
We
> have isolate the leak to one function.  We have removed everything but 2
> lines, se below. Is is possible that the dotNet environment dose not free
> the memory.

> public void TranslateXML( string strMsg )
> {
>     DOMDocument oDoc = new DOMDocumentClass( );

>     oDoc = null;
> }


 
 
 

MSXML, C# and huge memory leak

Post by Thomas Olsso » Fri, 03 May 2002 23:58:56


I don't think you should have to release the COM object manually unless you
do not want to rely on GC. The reference should be released when the wrapper
i "garabage collected". How have you identified you "huge memory leak"? It
can be quite tricky with GC to detect such leaks. If there is plenty of
memory GC seems not to be run very often.

/Thomas

--
Thomas Olsson, Vinga System AB, Sweden
http://www.vinga.se
(Reply adress is invalid to avoid spam)


> We found the problem...

> We have to call the release our self
> System.Runtime.InteropServices.Marshal.ReleasecomObject( oDoc );



> > Hi

> > I'm translateing a xml message and have to do it a lot.

> > We use MSXML ver. 4 and we have notice a huge memory leak in our
program.
> We
> > have isolate the leak to one function.  We have removed everything but 2
> > lines, se below. Is is possible that the dotNet environment dose not
free
> > the memory.

> > public void TranslateXML( string strMsg )
> > {
> >     DOMDocument oDoc = new DOMDocumentClass( );

> >     oDoc = null;
> > }

 
 
 

MSXML, C# and huge memory leak

Post by Thorir Danielsso » Sat, 04 May 2002 21:43:19


Hi, I work with Gunnar,

On a machine with 512MB of memory this code in a loop reached 2GB before we
shut it down.
Running GC.Collect() didn't seem to make any difference at all.

for(int i = 0; i<100000; i++)
{
    DOMDocument oDoc = new DOMDocumentClass( );
     oDoc = null;

Quote:}

GC.Collect();


> I don't think you should have to release the COM object manually unless
you
> do not want to rely on GC. The reference should be released when the
wrapper
> i "garabage collected". How have you identified you "huge memory leak"? It
> can be quite tricky with GC to detect such leaks. If there is plenty of
> memory GC seems not to be run very often.

> /Thomas

> --
> Thomas Olsson, Vinga System AB, Sweden
> http://www.vinga.se
> (Reply adress is invalid to avoid spam)



> > We found the problem...

> > We have to call the release our self
> > System.Runtime.InteropServices.Marshal.ReleasecomObject( oDoc );



> > > Hi

> > > I'm translateing a xml message and have to do it a lot.

> > > We use MSXML ver. 4 and we have notice a huge memory leak in our
> program.
> > We
> > > have isolate the leak to one function.  We have removed everything but
2
> > > lines, se below. Is is possible that the dotNet environment dose not
> free
> > > the memory.

> > > public void TranslateXML( string strMsg )
> > > {
> > >     DOMDocument oDoc = new DOMDocumentClass( );

> > >     oDoc = null;
> > > }

 
 
 

1. C# COM+ component leaking memory

Maybe you guys can help me with this memory leak.  I've created a COM+
component in C# to wrap retrieving a message off a MSMQ and dropping the
body of the message into the database.  The COM component is being called
from a multi-threaded console application.  Over the course of an hour, my
application consumes all the available memory on my test server.  I've
tracked the leak down to where my application instantiates and frees the
COM+ component.  I've commented out the function call to the component, but
that didn't clear up the leak.  It looks like merely creating and freeing
the component causes the leak.

Here's a bit of the COM: component:
using System;
using System.IO;
using System.Data;
using System.Messaging;
using System.Data.SqlClient;
using System.EnterpriseServices;

namespace Router.ComSvcs
{
    /// <summary>
    /// Retrieves messages from the MSMQ and logs them in the
    /// database, using the DTC to coordinate the transaction.
    /// </summary>
    [Transaction (TransactionOption.Required)]
    public class MessageAdapter : ServicedComponent
    {
        /// <summary>
        /// Default constructor - COM+ components cannot have
        /// constructors with parameters.
        /// </summary>
        public MessageAdapter ()
        {
        }

        // ... Public member functions ...

    }

Here's my call:
    Router.ComSvcs.MessageAdapter adapter = new
Router.ComSvcs.MessageAdapter ();
    // Removed the call to the public members of the component and it still
leaks.
    adapter.Dispose ();
    adapter = null;

Some questions:
1. Could this be a problem with the main application?  It is using
STAThread.
2. If I specify MTAThread in the main method of the console application,
does that threading model get inherited by all worker threads I create?

Hope you guys can help!

2. Ricoh 6200S DAE Anomalies?

3. C# unmanaged memory leak detection

4. TCP/IP Goodies...

5. Draw image HUGE memory load ??????

6. need static address & firewall

7. HUGE memory usage while loading images

8. help about the fft

9. aspnet_wp process taking up *huge* amounts of memory

10. MSXML and memory problems

11. Huge Form, Huge Headache (small classic question)

12. Interop memory leak with VB.NET to VC++

13. Slow Memory Leak - HELP!!!!