我有一个由动态数据生成的极其复杂的文档。最近我们使用IE8的用户出现了“Out of Memory”问题。但是,事实证明,在这个例子中,IE的所有版本似乎都有内存问题。任何回发(部分或全部)气球IE内存使用量每回发2-50mb。有了足够的使用量,在一个简单的页面上就可以轻松超过1GB的使用量(Chrome内存大约为30mb)。
我已经简化了代码以快速显示问题。
使用Visual Studio 2008创建.Net 3.5(在VS 2012中测试,问题仍然存在)
.aspx的:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="IEMemLeak.aspx.cs" Inherits="TestWebsite.IEMemLeak" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server" ID="ScriptManager" EnablePartialRendering="True" ></asp:ScriptManager>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
Aspx.cs:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace TestWebsite
{
public partial class IEMemLeak : Page
{
protected void Page_Load(object sender, EventArgs e)
{
PlaceHolder1.Controls.Clear();
PlaceHolder1.Controls.Add(new Button { ID = "PostbackButton", Text = "Click Me"});
//This is where we'd pull dynamic controls from databased templates. simplified as a for loop to create a lot of controls (makes the mem issue really stand out)
for (int i = 0; i < 500; i++)
{
TextBox textbox = new TextBox {ID = "TextBox" + i, Text = "abc" + i, CausesValidation = true};
RequiredFieldValidator requiredFieldValidator = new RequiredFieldValidator { ControlToValidate = "TextBox" + i};
PlaceHolder1.Controls.Add(textbox);
PlaceHolder1.Controls.Add(requiredFieldValidator);
}
}
}
}
我知道这不是最优雅的例子,但我认为这足以用于演示目的。
有没有人遇到过这个错误或类似错误(并管理了一个工作)?