ASP.NET UnManaged Memory Shoots Up,

C

Chetan Raj

Hi All,

We have a web-application in asp.net that interacts with legacy code
written in COM. The memory usage in aspnet_wp.exe increases every sec
and never reduces. Using the .NET performance counters, we found that
unmanaged memory was 90% of the total private bytes of aspnet_wp.exe.

We suspected that the COM code has memory leaks. So we made it as a
COM+ Service running as dllhost.exe. Surprisingly, there was no memory
increase in the DllHost.exe of this COM service, but aspnet_wp.exe's
memory was still shooting up. Again thru Performance counters we found
that unmanaged memory was taking around 80% of the total private bytes
of aspnet_wp.exe.

Now, can anyone help us in knowing the cause for the memory shoot up?
How to detect, which part of the code is responsible for the memory
increase? And what is holding on to the memory?

Thanking in advance for any help,
Chetan Raj
 
J

Jim Cheshire [MSFT]

Hi Chetan,

You can get a hang dump of the process to determine where the leak is. If
it's a native leak, it's easiest to use something like LeakDiag to find out
where the leak is. If you need assistance with one or both of those, you
can call us and we'll take care of you.

Jim Cheshire [MSFT]
MCP+I, MCSE, MCSD, MCDBA
Microsoft Developer Support
(e-mail address removed)

This post is provided "AS-IS" with no warranties and confers no rights.

--------------------
 
B

bruce barker

you have to manually release all com objects when you are done with them,
otherwise you are waiting for the gc to do it, which it may ignored for a
long time because the allocations (managed) are so small.

see

System.Runtime.InteropServices.Marshal.ReleaseComObject

this should be called when you are done with a com object (it will decrement
the reference counter in the com object and allow the com object to release
its resources).

-- bruce (sqlwork.com)
 
J

Jim Cheshire [MSFT]

It is also recommended that you do this in a loop while the return is not
0. The value returned by the call to ReleaseComObject is the reference
count.

Jim Cheshire [MSFT]
MCP+I, MCSE, MCSD, MCDBA
Microsoft Developer Support
(e-mail address removed)

This post is provided "AS-IS" with no warranties and confers no rights.


--------------------
 
C

Chetan Raj

We create a pool of 20-40 instances of the COM object and reuse these
instances for all the tasks. We are never done with them!

Thanks,
Chetan
 
S

Stephen Woolhead

There is a AddMemoryPressure function off the GC that allows you to tell the
GC that your small managed allocation is looking after a much bigger
unmanaged allocation, and that it should pay more attention to cleaning it
up, it's used something like this

class LargeUnmanagedContainer
{
private long _size;
LargeUnmanagedContainer ()
{
// Allocate a lot of unmanaged memory and
// set _size to the amout of memory used

GC.AddMemoryPressure(_size);

// other work
}

~LargeUnmanagedContainer()
{
GC.RemoveMemoryPressure(_size);
// other work
}
}

Never used it, remember it from a talk I was at several months ago, might
help force the GC to do some clean up for you.

Stephen.
 
C

Chetan Raj

Hi All,

We tried System.Runtime.InteropServices.Marshal.ReleaseComObject,
but that did not help.

aspnet_wp.exe still allocates unmanaged memory and it recyles when it
reaches 60% of total memory.

Whats causing aspnet_wp.exe to allocate so much unmanaged memory and
then recycle eventually?

Thanks in advance for any help,
Chetan Raj
 
C

Chetan Raj

hi Jim Cheshire,

I have taken a hang dump of aspnet_wp.exe. Now, where can i find
LeakDiag app. I searched the web for this tool. I could not find it. I
guess, it is an internal tool used by Microsoft support guys. How do I
get this tool?

I also used UMDH.exe to generate stack traces of heap allocation at
two different times. I then compared these dumps and generated
possible leaks using the same UMDH.exe. One of the BackTrace is shown
here : This points to a module which has no information. How do I
crack this?


001203F0 bytes in 0x12 allocations (@ 0x00010038) by: BackTrace15626
ntdll!RtlDebugAllocateHeap+000000FD
ntdll!RtlAllocateHeapSlowly+0000005A
ntdll!RtlAllocateHeap+000008BE
KERNEL32!LocalAlloc+00000074
793971C1 : <no module information>
79397306 : <no module information>
79395F71 : <no module information>
7933F2A9 : <no module information>
072D5224 : <no module information>


Thanks,
Chetan Raj
 
C

Chetan Raj

hi,

We ran the unmanaged code out of aspnet_wp.exe process by making it a
COM+ Service. The unmanaged code ran under DllHost.exe process. Even
then aspnet_wp.exe unmamged memory was increasing at higher rate. I
looked at the modules within aspnet_wp.exe process and made sure that
it does not contain any of our unmanged module within it.

Can any one explain this?

Thanks,
Chetan Raj
 
J

Jim Cheshire [MSFT]

AddMemoryPressure() is new in Whidbey.

Jim Cheshire [MSFT]
MCP+I, MCSE, MCSD, MCDBA
Microsoft Developer Support
(e-mail address removed)

This post is provided "AS-IS" with no warranties and confers no rights.


--------------------
 
J

Jim Cheshire [MSFT]

Chetan,

Without a memory dump, there is no way to say.

Jim Cheshire [MSFT]
MCP+I, MCSE, MCSD, MCDBA
Microsoft Developer Support
(e-mail address removed)

This post is provided "AS-IS" with no warranties and confers no rights.

--------------------
 
C

Chetan Raj

Hi All,

First of all, thanks for all of your replies.

I found the cause for the memory leak.

It is ....

XslTransform xslt = new XslTransform();
xslt.Load(Server.MapPath("NewInteraction.xslt"));

.....

This abysmally leaks UnManaged memory for each call!!

The following App proves that:

using System;
using System.Xml;
using System.Xml.Xsl;

namespace xslt
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
XmlDocument Xmlsectiondoc = new XmlDocument();

for(int i=0; i<1000; ++i)
{
Xmlsectiondoc.Load("E:\\Debug\\Bugs\\xmldoc.xml");
XslTransform xslt = new XslTransform();
xslt.Load("E:\\Program Files\\Interaction.xslt");
XmlDocument resultdata = new XmlDocument();
XmlReader reader = xslt.Transform(Xmlsectiondoc,null);
resultdata.Load(reader);
string m_sHTML = resultdata.InnerXml;
if((i%10)==0)
{
Console.WriteLine(i.ToString() + "." + " Calling GC.Collect()");
GC.Collect();
}
}
Console.ReadLine();
}
}
}



MicroSoft : When will this issue be fixed?

Thanks
Chetan Raj
 
C

Chetan Raj

Hi All,

First of all, thanks for all of your replies.

I found the cause for the memory leak.

It is ....

XslTransform xslt = new XslTransform();
xslt.Load(Server.MapPath("NewInteraction.xslt"));

.....

This abysmally leaks UnManaged memory for each call!!

The following App proves that:

using System;
using System.Xml;
using System.Xml.Xsl;

namespace xslt
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
XmlDocument Xmlsectiondoc = new XmlDocument();

for(int i=0; i<1000; ++i)
{
Xmlsectiondoc.Load("E:\\Debug\\Bugs\\xmldoc.xml");
XslTransform xslt = new XslTransform();
xslt.Load("E:\\Program Files\\Interaction.xslt");
XmlDocument resultdata = new XmlDocument();
XmlReader reader = xslt.Transform(Xmlsectiondoc,null);
resultdata.Load(reader);
string m_sHTML = resultdata.InnerXml;
if((i%10)==0)
{
Console.WriteLine(i.ToString() + "." + " Calling GC.Collect()");
GC.Collect();
}
}
Console.ReadLine();
}
}
}



MicroSoft : When will this issue be fixed?

Thanks
Chetan Raj
 
J

Jim Cheshire [MSFT]

Chetan,

Are you using any <msxsl:script> elements in your XSLT?

You should not be loading the XSLT in every iteration. Load it once and
reuse it as needed.

Jim Cheshire [MSFT]
MCP+I, MCSE, MCSD, MCDBA
Microsoft Developer Support
(e-mail address removed)

This post is provided "AS-IS" with no warranties and confers no rights.

--------------------
From: (e-mail address removed) (Chetan Raj)
Newsgroups: microsoft.public.dotnet.framework.aspnet,microsoft.public.dotnet.framework
Subject: Re: ASP.NET UnManaged Memory Shoots Up,
Date: 19 Aug 2004 01:15:49 -0700
Organization: http://groups.google.com
Lines: 68
Message-ID: <[email protected]>
References: <[email protected]>
<[email protected]>
NNTP-Posting-Host: 164.164.88.134
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: posting.google.com 1092903350 16583 127.0.0.1 (19 Aug 2004 08:15:50 GMT)
X-Complaints-To: (e-mail address removed)
NNTP-Posting-Date: Thu, 19 Aug 2004 08:15:50 +0000 (UTC)
Path: cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.s
ul.t-online.de!t-online.de!newsfeed.icl.net!proxad.net!postnews2.google.com!
not-for-mail
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.framework:77810 microsoft.public.dotnet.framework.aspnet:256106
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

Hi All,

First of all, thanks for all of your replies.

I found the cause for the memory leak.

It is ....

XslTransform xslt = new XslTransform();
xslt.Load(Server.MapPath("NewInteraction.xslt"));

....

This abysmally leaks UnManaged memory for each call!!

The following App proves that:

using System;
using System.Xml;
using System.Xml.Xsl;

namespace xslt
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
XmlDocument Xmlsectiondoc = new XmlDocument();

for(int i=0; i<1000; ++i)
{
Xmlsectiondoc.Load("E:\\Debug\\Bugs\\xmldoc.xml");
XslTransform xslt = new XslTransform();
xslt.Load("E:\\Program Files\\Interaction.xslt");
XmlDocument resultdata = new XmlDocument();
XmlReader reader = xslt.Transform(Xmlsectiondoc,null);
resultdata.Load(reader);
string m_sHTML = resultdata.InnerXml;
if((i%10)==0)
{
Console.WriteLine(i.ToString() + "." + " Calling GC.Collect()");
GC.Collect();
}
}
Console.ReadLine();
}
}
}



MicroSoft : When will this issue be fixed?

Thanks
Chetan Raj



(e-mail address removed) (Jim Cheshire [MSFT]) wrote in message
AddMemoryPressure() is new in Whidbey.

Jim Cheshire [MSFT]
MCP+I, MCSE, MCSD, MCDBA
Microsoft Developer Support
(e-mail address removed)

This post is provided "AS-IS" with no warranties and confers no rights.
 
P

Parco

Use Dispose() method in every unmanaged objects after you have used and
won't be used any more.
This method will release all memory it used up while it was working.


Chetan Raj said:
Hi All,

First of all, thanks for all of your replies.

I found the cause for the memory leak.

It is ....

XslTransform xslt = new XslTransform();
xslt.Load(Server.MapPath("NewInteraction.xslt"));

....

This abysmally leaks UnManaged memory for each call!!

The following App proves that:

using System;
using System.Xml;
using System.Xml.Xsl;

namespace xslt
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
XmlDocument Xmlsectiondoc = new XmlDocument();

for(int i=0; i<1000; ++i)
{
Xmlsectiondoc.Load("E:\\Debug\\Bugs\\xmldoc.xml");
XslTransform xslt = new XslTransform();
xslt.Load("E:\\Program Files\\Interaction.xslt");
XmlDocument resultdata = new XmlDocument();
XmlReader reader = xslt.Transform(Xmlsectiondoc,null);
resultdata.Load(reader);
string m_sHTML = resultdata.InnerXml;
if((i%10)==0)
{
Console.WriteLine(i.ToString() + "." + " Calling GC.Collect()");
GC.Collect();
}
}
Console.ReadLine();
}
}
}



MicroSoft : When will this issue be fixed?

Thanks
Chetan Raj



(e-mail address removed) (Jim Cheshire [MSFT]) wrote in message
AddMemoryPressure() is new in Whidbey.

Jim Cheshire [MSFT]
MCP+I, MCSE, MCSD, MCDBA
Microsoft Developer Support
(e-mail address removed)

This post is provided "AS-IS" with no warranties and confers no rights.
 
G

Guest

I've been following this with great interest, because I'm seeing the same
thing in one of my COM objects. I've checked the object by invoking it from a
VB 6 program and running Purify against it--absolutely no memory leaks or
overwrites, no COM leaks, no handle leaks. I've done all the stuff suggested
earlier in this thread, including using ReleaseComObject in a loop.

I'd like to give the Dispose method a try...do I just invoke it from the
object? For example, something like:

MyCOMObj.Dispose()

By the way, the symptom I am seeing is that the first time an instance of
the COM object is allocated by apsnet_wp, its memory usage jumps from about
4M to about 25M. Then, every use thereafter increases by about 16K...which is
not much, but it does add up.

Parco said:
Use Dispose() method in every unmanaged objects after you have used and
won't be used any more.
This method will release all memory it used up while it was working.


Chetan Raj said:
Hi All,

First of all, thanks for all of your replies.

I found the cause for the memory leak.

It is ....

XslTransform xslt = new XslTransform();
xslt.Load(Server.MapPath("NewInteraction.xslt"));

....

This abysmally leaks UnManaged memory for each call!!

The following App proves that:

using System;
using System.Xml;
using System.Xml.Xsl;

namespace xslt
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
XmlDocument Xmlsectiondoc = new XmlDocument();

for(int i=0; i<1000; ++i)
{
Xmlsectiondoc.Load("E:\\Debug\\Bugs\\xmldoc.xml");
XslTransform xslt = new XslTransform();
xslt.Load("E:\\Program Files\\Interaction.xslt");
XmlDocument resultdata = new XmlDocument();
XmlReader reader = xslt.Transform(Xmlsectiondoc,null);
resultdata.Load(reader);
string m_sHTML = resultdata.InnerXml;
if((i%10)==0)
{
Console.WriteLine(i.ToString() + "." + " Calling GC.Collect()");
GC.Collect();
}
}
Console.ReadLine();
}
}
}



MicroSoft : When will this issue be fixed?

Thanks
Chetan Raj



(e-mail address removed) (Jim Cheshire [MSFT]) wrote in message
AddMemoryPressure() is new in Whidbey.

Jim Cheshire [MSFT]
MCP+I, MCSE, MCSD, MCDBA
Microsoft Developer Support
(e-mail address removed)

This post is provided "AS-IS" with no warranties and confers no rights.
 

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

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top