问题描述:

I have a GridView that is bound to an ObjectDataSource that is calling a Business Service object which returns a List<> of POCO's.

Recently my client removed the Page Limit number on the GridView due to their customer's request. This resulted in the GridView displaying over 10K items.

When this page is called we're seeing the ASP.NET process eat up roughly 30MB on each refresh and not letting it go. (eventually the web server throws an out of memory exception)

I'm 100% certain this is not the BSO (I've created a page that calls the BSO 20 times and seen no memory leak). I ran the ANTS Profiler and saw that most of the memory is indeed from the Web UI.

<asp:TextBox ID="uxQuery" runat="server" Width="300px" MaxLength="300"></asp:TextBox>

<asp:Button ID="uxSearch" runat="server" Text="Search" OnClick="uxSearch_Click" />

<asp:GridView ID="GridView1" Width="100%" Visible="True" DataSourceID="MyDataSource"

runat="server" AllowSorting="True" AutoGenerateColumns="False"

OnRowDataBound="GridView1_RowDataBound" EnableViewState="False">

<PagerSettings FirstPageText="&lt;&lt;" LastPageText="&gt;&gt;" Mode="NumericFirstLast"

NextPageText="&gt;" PreviousPageText="&lt;"></PagerSettings>

<Columns>

<asp:TemplateField HeaderText="Name" SortExpression="OrganizationName">

<ItemTemplate>

<asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Eval("Name") %>' CommandName="Name"

CommandArgument='<%# Eval("ID") %>'></asp:LinkButton>

</ItemTemplate>

</asp:TemplateField>

<asp:BoundField DataField="CityName" HeaderText="City" SortExpression="CityName" />

<asp:BoundField DataField="PhoneNumber" HeaderText="Phone" SortExpression="PhoneNumber" />

</Columns>

<HeaderStyle CssClass="MasterHeader" />

<AlternatingRowStyle CssClass="AlternateRow" />

</asp:GridView>

<asp:ObjectDataSource ID="MyDataSource" runat="server" OldValuesParameterFormatString="original_{0}"

SelectMethod="GetBySearchString" TypeName="BLL.BSO.SummaryBSO"

SortParameterName="sortExpression" EnablePaging="True">

<SelectParameters>

<asp:ControlParameter ControlID="uxQuery" Name="searchString" PropertyName="Text"

Type="String" />

</SelectParameters>

</asp:ObjectDataSource>

I've talked my client and customer out of this "feature" but I'm still curious why the memory leak exists.

网友答案:

I doubt it's the GridView. Too many people are using it; if it had a memory leak, others would have noticed and reported it.

If you're sure it's not in your BLL, then that leaves the glue logic in between, or possibly something peripheral, but related.

Are you using any static references?

Are you assigning any event handlers? There's a common memory leak scenario that involves assigning event handlers, and not unassigning them later. One unpleasant corner case is where a the event handler references are held by a long-lifetime or static object.

Are you calling all required Dispose() calls? Do any of the associated objects use unmanaged memory?

相关阅读:
Top