0

I have a classic asp.net page in .net 4.6.1. It loads 4 MB of data (they want it on one page) and no matter I simplify it, the IIS Worker Process w3wp.exe eats up a Gig of data, and never expires anything or gives any memory back. Why?

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
         <asp:GridView ID="gvSelectionList" runat="server" AutoGenerateColumns="false" CssClass="LPSCriteriaSelection" EnableViewState="False">
            <Columns>
                <asp:TemplateField HeaderText="SerialNumber">
                    <ItemTemplate>
                        <asp:HyperLink ID="hlSerialNumber" Text='<%#GetSerialNumberText(Container.DataItem)%>' />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
</asp:Content>

Here's the code

using System;
using System.Collections.Generic;
using System.Web.UI;

public partial class _Default : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(this.IsPostBack) return;
        ExpandableSelections items = new ExpandableSelections();
        if(items.Count == 0) return;
        this.gvSelectionList.DataSource = items;
        this.gvSelectionList.DataBind();
    }
    protected string GetSerialNumberText(object dataItem)
    {
        SerialNumberData item = (SerialNumberData)dataItem;
        return item.SerialNumber;
    }
}
public class SerialNumberData
{
    public string SerialNumber { get; set; }
    public SerialNumberData(string data) { SerialNumber = data; }
}
public class ExpandableSelections : List<SerialNumberData>
{
    internal ExpandableSelections()
    {   // Emulate database call
        for (int i = 1; i < 72000; i++)
            this.Add(new SerialNumberData("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"));
    }
}
  • Possible duplicate of [High memory usage with w3wp application pool IIS 7](http://stackoverflow.com/questions/9666356/high-memory-usage-with-w3wp-application-pool-iis-7) – CodeCaster Jan 18 '17 at 16:58

1 Answers1

0

A call to Microsoft revealed calling .Dispose() on the grid itself will make it more readily available to Garbage Collection, but in this example the GC thread was often blocked (said they couldn't see by what -- antivirus?) and, because we only needed a read-only GridView,

I found it far better to simply replace the GridView with a classic <% FunctionCall(); %> and in that call write the html out directly with Reponse.Write().

This used far less RAM and would always return it on subsequent page loads.