Application pool requested a recycle because it reached its virtual memory limit

Donald Symmons 2,856 Reputation points

I hosted a web application on a (Live server) shared hosting, and did not get any issue until today when I decided to test-run it. I registered and logged in the web application with the test login details; I was redirected to the dashboard, but after some seconds I was redirected back to the login page (I got logged out). I don't know how this happened, it quickly logs me out and redirects me to login page. After this persisted, I contacted my hosting company then I was told that I maxed out my resource which was causing the issue. A worker process with id serving application pool 'website domain name(domain)(4.0)(pool) has requested a recycle because it reached its virtual memory limit.

To be honest, I don't know how this happened because the application has been on a live server for months without this issue. However, I will like to know if this can be resolved and also prevent a re-occurrence?

Please can anyone help me with details of how to resolve this?

Could it be that there is something I did or didn't do in my web.config file?

    <add name="ConString" connectionString="My Connection String goes here"/>
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
  <sessionState timeout="30"></sessionState>
    <trust level="Full" />
    <authentication mode="Forms">
      <forms timeout="30" cookieless="UseCookies" loginUrl="" defaultUrl="" slidingExpiration="true" />
      <deny users="?" />
    <compilation debug="true" targetFramework="4.7.2" />
    <httpRuntime targetFramework="4.7.2" maxRequestLength="3145728" />
    <customErrors mode="Off" />
    <pages enableEventValidation="false">
        <add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" />
	<machineKey validationKey="308A5193B77D18BB33F286DCC941A54331AE8D000104EAC1DB843D98B1CB457AF9A813B4D5D7D77220987AC8EA478401577194FC20E6CCE8ACEC159C5C59D754" decryptionKey="46C25F7D8BFDE6DAF886AEC2706EFA6A2706C43C752B69C82D5B13A29EA246C1" validation="SHA1" decryption="AES" />
    <defaultDocument enabled="true">
        <clear />
        <add value="Default.aspx" />
        <jsonSerialization maxJsonLength="2147483644"></jsonSerialization>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="" newVersion="" />
        <assemblyIdentity name="BouncyCastle.Crypto" publicKeyToken="0e99375e54769942" culture="neutral" />
        <bindingRedirect oldVersion="" newVersion="" />
        <assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
        <bindingRedirect oldVersion="" newVersion="" />
        <assemblyIdentity name="Microsoft.Extensions.DependencyInjection" publicKeyToken="adb9793829ddae60" culture="neutral" />
        <bindingRedirect oldVersion="" newVersion="" />
        <assemblyIdentity name="Microsoft.Extensions.Logging.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
        <bindingRedirect oldVersion="" newVersion="" />
        <assemblyIdentity name="Microsoft.Extensions.Logging" publicKeyToken="adb9793829ddae60" culture="neutral" />
        <bindingRedirect oldVersion="" newVersion="" />

I also have this page load event on every page on the application

protected void Page_Load(object sender, EventArgs e)
            if (this.Page.User.Identity.IsAuthenticated && Session["user"] != null)
                labelid.Text = Session["user"].ToString();
            Response.AppendHeader("Pragma", "no-cache");

I have also been thinking if it came as a result of using 3rd party API like ip2location to get user's local time zone

private void LastLogin()
            string connectionString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
            using (SqlConnection con = new SqlConnection(connectionString))
                using (SqlCommand cmd = new SqlCommand("SELECT LastLogin FROM UserTable WHERE id = @id", con))
                    cmd.Parameters.AddWithValue("@id", Session["user"]);
                    DateTime time1 = Convert.ToDateTime(Session["LastLogin"]);
                    TimeZoneInfo serverTimeZone = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
                    TimeZoneInfo userTimeZone = TimeZoneInfo.FindSystemTimeZoneById(GetTimeZoneNameByOffsetTime(this.GetLocation().time_zone.Replace("+", "")));
                    DateTime userLocalTime = TimeZoneInfo.ConvertTime(time1, serverTimeZone, userTimeZone);
                    Timelbl.Text = userLocalTime.ToString("dddd, MMMM d, yyyy h:mm tt");

Internet Information Services
Microsoft Technologies based on the .NET software framework.
3,459 questions
A set of technologies in the .NET Framework for building web applications and XML web services.
3,312 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,131 questions
{count} votes

2 answers

Sort by: Most helpful
  1. AgaveJoe 26,166 Reputation points

    1. I hope recycling of the dedicated IIS Application pool for websites will not cause any issues on my application ?

    Recycling the application pool clears Session and creates a new encryption key (default setting). A new encryption key invalidates any current authenticated users.

    2. Will this issue re-occur in the future?

    If there is a memory leak then yes it will happen again. A memory leak is code that stores information in volatile memory and never releases the memory. It could be code that is slowly using up memory over time, a process that stores a lot of data in memory, or a little of both.

    3. And will I continue to do this each time this happens?

    Probably, it depends on the cause. Finding and fixing the bug is a better solution.

  2. Donald Symmons 2,856 Reputation points

    I think I know why my virtual memory was used up by my application. I left a whole lot of Database connections open in my code. I left about 60-70% connections open on each page and did not close them. That's why my application used up its memory. Those open connections were consuming resources on the server.

    0 comments No comments