ASP.Net - w3wp consuming memory on basic web application

148 views Asked by At

I created a very basic web application in an attempt to isolate what I think might be a memory leak with a production web app in which the w3wp process consumes memory with each login and doesn’t appear to release that memory. I noticed that my very basic web app was also consuming memory within the iisexpress/w3wp process simply by running the application and hitting refresh on the page. After refreshing the page 20 times the hosting process (iisexpress/w3wp) consumes between 5 MB and 14 MB of memory that it doesn't release. When I take snapshots of the memory using VS 2015's diagnostic tools the amount of memory seems to stay relatively flat.

What would cause this amount of memory to be consumed by the hosting process? What can be done to reduce or eliminate the memory usage?

Out of curiosity I added a call to garbage collection, GC.Collect(3), in the Page_Load event and that seem to keep the memory usage flat. Looking at the memory snapshots before and after the GC.Collect() call doesn't show anything consistently being cleaned up. And this works only if I call GC for each page load. Calling GC each time doesn't seem like much of a solution though.

I am running this on my development machine which is running Windows 10. I am using the default host settings for both IISExpress and IIS. The web app is built from an empty 4.6.1 asp.net web app project. The web app has a single web form page, login.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="WebFormTesting.Login" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="login" method="post" runat="server">
        <div>
            <div style="height: 250px; width: 500px; position: absolute; left: 380px; top: 120px;">
                <div class="clsText10">
                    <asp:TextBox ID="txtUsername" TabIndex="1" Width="160px" runat="server" ToolTip="Enter User Name"
                        MaxLength="100" Style="position: absolute; right: 130px; top: 5px;"></asp:TextBox>
                    <br />
                    <asp:TextBox ID="txtPassword" TabIndex="2" runat="server" ToolTip="Enter Password"
                        MaxLength="25" Width="160px" TextMode="Password" Style="position: absolute; right: 130px; top: 50px;"></asp:TextBox>
                    <br />
                    <asp:Label ID="Label1" runat="server" CssClass="clsText10"
                        Style="font-weight: bold; position: absolute; right: 120px; top: 85px;" Text="(Please note: Password values are case sensitive.)"></asp:Label>
                    <asp:Button ID="btnLogin" TabIndex="3" runat="server" Text="Login" CssClass="btn btn-primary"
                        ToolTip="Verify User Name and Password" OnClick="btnLogin_Click" Width="120"
                        Style="position: absolute; right: 180px; top: 180px;"></asp:Button>
                    <div>
                        <asp:Label ID="lblUsername" Text="User Name:&nbsp;" runat="server" Style="position: absolute; right: 310px; top: 5px;"></asp:Label>
                        <br />
                        <asp:Label ID="lblPassword" Text="Password:&nbsp;" runat="server" Style="position: absolute; right: 310px; top: 50px;"></asp:Label>
                        <br />
                        <asp:Label ID="txtError" runat="server" Visible="true" Style="z-index: 100; width: 450px; text-align: right; position: absolute; top: 115px; right: 130px;"></asp:Label>
                    </div>
                </div>
            </div>
        </div>
    </form>
</body>
</html>

With the code behind page, Login.aspx.cs:

using System;

namespace WebFormTesting
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            //
        }
    }
}
0

There are 0 answers