GC memory pressure problem in using unmanaged components

N

Noman Ali

Hi,

We are facing a strange problem in our ASP. NET website. Some times it gives
the following unhandled exception.

Error Message: Exception of type System.Web.HttpUnhandledException was thrown.
Detailed Error Message: System.InvalidOperationException: There has been an
overflow or underflow in GC memory pressure. The possible cause is unbalanced
AddMemoryPressure and RemoveMemoryPressure calls.
at System.MemoryWatcher.AddMemoryPressure(Int64 size)
at System.GC.AddMemoryPressure(Int64 pressure)
at WebApplication1.CFileUtils.ProcessFile(String filename)
at WebApplication1.CBanner.CreateStringTag(String appPath, Int32 width,
Int32 height, String& ext)
at WebApplication1.CAdRotator.DisplayBanners(HtmlTable table, String
position, String queryStr, String[]& displayed)
at WebApplication1.TopBanner.Page_Load(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain()

I already did some research on it and found that it is caused when you add
and remove unbalanced memory pressure on GC. But we are not doing that. The
exception comes during peak hours of our site and it comes randomly normally
after 12-14 hours daily and after that we needs to restart the asp .net
worker process. The worker process uses around 50% of the system memory
during this abnormal behaviour. The web application heavily uses some
unmanaged COM components for PDF and image manupulation.

What i had done so far, i forefully calls garbage collection after every
hour so that COM components will be garbage collected. I am identifying
memory leaks in the web application but still i think the problem is
different.

Any suggestion, comments or experience will be welcome.

Regards,
Noman Ali
 
B

bruce barker

you are probably "leaking" unmanaged com memory by not releasing com
references when done, but rather letting the gc do it.

when your code is done with a com object it should call
Marshal.ReleaseComObject. also you should never use more than one dot when
referencing a com object or you will have a leak.

ex:

// create com object
MyComObject a = new MyComObject();

// call 2 dot method wrong way
a.b.c(); // leaks b, only gc will release

// call 2 dot correct

MyComBType b = a.b;
b.c();
Marshal.ReleaseComObject(b);
b = null;

// release com object
Marshal.ReleaseComObject(a);
a = null;

tedious, but necessary.

-- bruce (sqlwork.com)
 
N

Noman Ali

Hi bruce barker,

Thanks for the reply. There is a probablity of memory leak but i dont think
that the given exception is a result of memory leak. Normally memory leaks
results in an out of memory exception. However the given exception is related
to unbalaced addition in GC memory pressure.

The important thing is that we are using ASP . NET 1.1 and
System.GC.AddMemoryPressure is not available in .NET 1.1 version.

Regards,
Noman Ali

bruce barker said:
you are probably "leaking" unmanaged com memory by not releasing com
references when done, but rather letting the gc do it.

when your code is done with a com object it should call
Marshal.ReleaseComObject. also you should never use more than one dot when
referencing a com object or you will have a leak.

ex:

// create com object
MyComObject a = new MyComObject();

// call 2 dot method wrong way
a.b.c(); // leaks b, only gc will release

// call 2 dot correct

MyComBType b = a.b;
b.c();
Marshal.ReleaseComObject(b);
b = null;

// release com object
Marshal.ReleaseComObject(a);
a = null;

tedious, but necessary.

-- bruce (sqlwork.com)


Noman Ali said:
Hi,

We are facing a strange problem in our ASP. NET website. Some times it gives
the following unhandled exception.

Error Message: Exception of type System.Web.HttpUnhandledException was thrown.
Detailed Error Message: System.InvalidOperationException: There has been an
overflow or underflow in GC memory pressure. The possible cause is unbalanced
AddMemoryPressure and RemoveMemoryPressure calls.
at System.MemoryWatcher.AddMemoryPressure(Int64 size)
at System.GC.AddMemoryPressure(Int64 pressure)
at WebApplication1.CFileUtils.ProcessFile(String filename)
at WebApplication1.CBanner.CreateStringTag(String appPath, Int32 width,
Int32 height, String& ext)
at WebApplication1.CAdRotator.DisplayBanners(HtmlTable table, String
position, String queryStr, String[]& displayed)
at WebApplication1.TopBanner.Page_Load(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain()

I already did some research on it and found that it is caused when you add
and remove unbalanced memory pressure on GC. But we are not doing that. The
exception comes during peak hours of our site and it comes randomly normally
after 12-14 hours daily and after that we needs to restart the asp .net
worker process. The worker process uses around 50% of the system memory
during this abnormal behaviour. The web application heavily uses some
unmanaged COM components for PDF and image manupulation.

What i had done so far, i forefully calls garbage collection after every
hour so that COM components will be garbage collected. I am identifying
memory leaks in the web application but still i think the problem is
different.

Any suggestion, comments or experience will be welcome.

Regards,
Noman Ali
 
Joined
Jan 29, 2011
Messages
1
Reaction score
0
I am also facing the same problem. But this started very recently. And it is starting on peak hours only. I am using Dispose method after every COM object usuage. So whether Marshal.ReleaseComObject help for me ? I am also using 1.1 framework. Any other suggestions ?

Jobin Johny

Noman Ali said:
Hi bruce barker,

Thanks for the reply. There is a probablity of memory leak but i dont think
that the given exception is a result of memory leak. Normally memory leaks
results in an out of memory exception. However the given exception is related
to unbalaced addition in GC memory pressure.

The important thing is that we are using ASP . NET 1.1 and
System.GC.AddMemoryPressure is not available in .NET 1.1 version.

Regards,
Noman Ali

"bruce barker" wrote:

> you are probably "leaking" unmanaged com memory by not releasing com
> references when done, but rather letting the gc do it.
>
> when your code is done with a com object it should call
> Marshal.ReleaseComObject. also you should never use more than one dot when
> referencing a com object or you will have a leak.
>
> ex:
>
> // create com object
> MyComObject a = new MyComObject();
>
> // call 2 dot method wrong way
> a.b.c(); // leaks b, only gc will release
>
> // call 2 dot correct
>
> MyComBType b = a.b;
> b.c();
> Marshal.ReleaseComObject(b);
> b = null;
>
> // release com object
> Marshal.ReleaseComObject(a);
> a = null;
>
> tedious, but necessary.
>
> -- bruce (sqlwork.com)
>
>
> "Noman Ali" wrote:
>
> > Hi,
> >
> > We are facing a strange problem in our ASP. NET website. Some times it gives
> > the following unhandled exception.
> >
> > Error Message: Exception of type System.Web.HttpUnhandledException was thrown.
> > Detailed Error Message: System.InvalidOperationException: There has been an
> > overflow or underflow in GC memory pressure. The possible cause is unbalanced
> > AddMemoryPressure and RemoveMemoryPressure calls.
> > at System.MemoryWatcher.AddMemoryPressure(Int64 size)
> > at System.GC.AddMemoryPressure(Int64 pressure)
> > at WebApplication1.CFileUtils.ProcessFile(String filename)
> > at WebApplication1.CBanner.CreateStringTag(String appPath, Int32 width,
> > Int32 height, String& ext)
> > at WebApplication1.CAdRotator.DisplayBanners(HtmlTable table, String
> > position, String queryStr, String[]& displayed)
> > at WebApplication1.TopBanner.Page_Load(Object sender, EventArgs e)
> > at System.Web.UI.Control.OnLoad(EventArgs e)
> > at System.Web.UI.Control.LoadRecursive()
> > at System.Web.UI.Control.LoadRecursive()
> > at System.Web.UI.Control.LoadRecursive()
> > at System.Web.UI.Control.LoadRecursive()
> > at System.Web.UI.Control.LoadRecursive()
> > at System.Web.UI.Page.ProcessRequestMain()
> >
> > I already did some research on it and found that it is caused when you add
> > and remove unbalanced memory pressure on GC. But we are not doing that. The
> > exception comes during peak hours of our site and it comes randomly normally
> > after 12-14 hours daily and after that we needs to restart the asp .net
> > worker process. The worker process uses around 50% of the system memory
> > during this abnormal behaviour. The web application heavily uses some
> > unmanaged COM components for PDF and image manupulation.
> >
> > What i had done so far, i forefully calls garbage collection after every
> > hour so that COM components will be garbage collected. I am identifying
> > memory leaks in the web application but still i think the problem is
> > different.
> >
> > Any suggestion, comments or experience will be welcome.
> >
> > Regards,
> > Noman Ali
 

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top