English

Problem: The ASP.NET worker process progressively increases memory usage

Description

When the Web server is experiencing extreme usage conditions for prolonged periods of time and the ASP.NET application uses the ArcGIS Server ADF for .NET, the ASP.NET worker process begins to increase its usage of memory and in some cases restarts.

Cause

The Microsoft .Net Framework garbage collector is not initialized under these extreme conditions to clear the ASP.NET worker process memory.

Solution or Workaround

The solution is to invoke the Garbage Collector explicitly within the application and wait for pending finalizers. This is a heavy process, so it is recommended to only induce the garbage collector after every 'n' requests.

The following code demonstrates how achieve this for C# and VB.NET. Experiment with the interval to achieve the maximum performance for the application.

C# Applications
For C# applications, open and edit Global.asax.cs

1)Add m_request variable inside Global class:

Code:
private int m_request = 0;

2)Edit Application_EndRequest function:

Code:
protected void Application_EndRequest(Object sender, EventArgs e)
{
if (m_request % 10 == 0)
{
GC.Collect();
GC.WaitForPendingFinalizers();
}
m_request++;
}

VB.Net Applications
For VB.Net applications, open and edit Global.asax.vb

1)Add m_request variable inside Global class:

Code:
Dim m_request = 0

2)Add Application_EndRequest function:

Code:
Sub Application_EndRequest(ByVal sender As Object, ByVal e As EventArgs)
If m_request Mod 10 = 0 Then
GC.Collect()
GC.WaitForPendingFinalizers()
End If
m_request = m_request + 1
End Sub