Friday, July 29, 2005

Leak by Apache aspdotnet module


It turns out to be Apache aspdotnet mod bug

This is a bug reported from Apache site:
We are doing production testing with our application, Oracle ODP.NET, and
mod_aspdotnet and noticed memory leaks occuring within the Apache process with
mod_aspdotnet installed. Our application does not leak with IIS or the Casini
web server. The objects which are not GC'd are those requiring finalization. I
examined the running process with WinDBG and SOS and found that the finalizer
thread in the application domain was stalled waiting on on a event sync for
one of the application STA model threads. I have made a test change in
mod_aspdotnet.cpp which converts the application threads from STA to MTA and
the problem seems to go away. Here is the code change (2 places):
Old:
// Check that THIS thread is coinitialized.
HRESULT hr = CoInitialize(NULL);
if (hr == RPC_E_CHANGED_MODE)
hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);


New:
// Check that THIS thread is coinitialized.
HRESULT hr = CoInitializeEx(NULL,COINIT_MULTITHREADED);
// if (hr == RPC_E_CHANGED_MODE)
// hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);

After making this changed, I verified that all threads are MTA and that the
finalizer is not stalled. I have run several high throughput tests with our
application hitting both the 2.0 mod_aspdotnet and my modified module and the
modified module does not leak managed objects over 24 hour periods.

Friday, July 22, 2005

.NET memory leak




Tried to fix .NET (C#) memory leak.

Our software architecture is based on Apache, Tomecat, .NET remoting and .NET framework.

I used purifyplus from IBM (Rational) to profile our codes and found out the behavior for garbage collector of .NET platform is strange, it does not perform garbage collection until I force it to do so.

From the above observation, I decided to call GC.collect() in one of the thread in the program every 15 secs. It seems to be helpful. ( but why??)

I also fixed the DBConcurrencyException which could causes leak when it happens. DBConcurrencyException is thrown by the ADO.NET codes when the database data is out of sync with the memory version.

Also see:
http://www.c-sharpcorner.com/Code/2002/Aug/GCinNet.asp

http://www.codeproject.com/dotnet/garbagecollection.asp

http://www.developer.com/net/csharp/article.php/3343191

http://blogs.msdn.com/stevenpr/archive/2004/07/26/197254.aspx

http://memprofiler.com/


----------