为什么这个泄漏的记忆在8?

时间:2011-11-17 14:51:40

标签: asp.net memory-leaks updatepanel

编辑2 -

重新创建 - (我希望)

创建一个空的asp.net项目,添加default.aspx和about.aspx

将此代码用于default.aspx文件:

http://pastebin.com/4Ri1BufM

这适用于about.aspx

http://pastebin.com/Ni9dZL7c

构建并对其进行筛选。单击按钮,然后单击链接。 Sieve现在应该列出1个内存泄漏。

这种简单的布局将服务器按钮放在面板中。如果单击它,然后单击“离开”链接,则sIEve报告1内存泄漏:

http://localhost:2605/Default.aspx  (1 reference)
<INPUT value="partial postback" type=submit name=ctl01 >

Aspx来源:

<%@ Page Title="Home Page" Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
    Inherits="LeakTestProject._Default" %>
<html>
<head>
    <title></title>
</head>
<body>
    <form id="Form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Button Text="partial postback" runat="server" />
        </ContentTemplate>
    </asp:UpdatePanel>
    </form>
    <a href="SomeOtherPage.aspx" >leave</a>
</body>
</html>

我认为我已经在我的应用程序中找到了此源的内存泄漏。

有人能够解释为什么会发生这种情况,以及如何解决这个问题?

(注意 - 没有运行服务器端代码)

编辑 -

这是生成的html:

<html>
<head>
    <title></title>
</head>
<body>
    <form method="post" action="Default.aspx" id="Form1">
<div class="aspNetHidden">
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTUzNzM3OTMxMmRk27mKixZYS2MtHiuw7SZF6+1A/CkWRnnarcN2a05yCJs=" />
</div>

<script type="text/javascript"> 
//<![CDATA[
var theForm = document.forms['Form1'];
if (!theForm) {
    theForm = document.Form1;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>


<script src="/WebResource.axd?d=_lxNoU5aYdEC_WWnUhGTN0VgFQnwFJ1fkZBkPhUGNITY1Tt87f4CGSPd9dhq2TD9I8lv5ljTGi956KpbHSLq3ebld0t7nKLON7Hc04CCAwA1&amp;t=634525784292792916" type="text/javascript"></script>


<script src="/ScriptResource.axd?d=0VE3fsyoY2cTFnat6m0YjE4OCCjVV0jmjSC6wigMBEOHyKW8kewBrhtJnBFIn73VSWcGW45QXwelC5m-1iZoornC8qWpZ-kXP-Y38e49qW1TbssOgo419ZWtVHSVmIpSg9CvXOQzUBClAjuHORyX5Q2&amp;t=ffffffffbd2983fc" type="text/javascript"></script>
<script type="text/javascript"> 
//<![CDATA[
if (typeof(Sys) === 'undefined') throw new Error('ASP.NET Ajax client-side framework failed to load.');
//]]>
</script>

<script src="/ScriptResource.axd?d=DBlWOXkmp0ycsSicGEZhACmLuhW1VF8BppK-Uj8ijyjhFxx7MTG8NW0gLl3IJ6TyEo2rAMfLCQ9rO_bk2wDCcpyT3Df6CN-TLMAA575gUNAjTSzC6U1koagV2FYRmu4TNsAgoEjhkN6fJX3lENf7Bw2&amp;t=ffffffffbd2983fc" type="text/javascript"></script>
<div class="aspNetHidden">

    <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgLZvOXNBgKiwImNCx8fSMXEwq+V+5yrnoaTcidPwoJw3ebm6DJQ1D3fVVAL" />
</div>
    <script type="text/javascript"> 
//<![CDATA[
Sys.WebForms.PageRequestManager._initialize('ScriptManager1', 'Form1', ['tUpdatePanel1','UpdatePanel1'], [], [], 90, '');
//]]>
</script>

    <div id="UpdatePanel1">

            <input type="submit" name="ctl01" value="partial postback" />

</div>
    </form>
    <a href="About.aspx" >leave</a>
</body>
</html>

2 个答案:

答案 0 :(得分:0)

根据http://www.codeproject.com/KB/ajax/jqmemleak.aspx,有一个内存泄漏听起来很像你正在经历的。

请参阅“迭代2 - 内存泄漏”

使用名为'SIEve'的工具,他声明'你可以看到,每次点击刷新时,它都会创建一组新的输入元素而不会破坏之前的输入元素。 “

他的修复程序是一个调用Update面板清理钩子的JQuery插件。你可以试试这个吗?

(function($) {
    $.fn.Disposable = function(cln) {
        return this.each(function() {
            var el = this;
            if (!el.dispose) {
                el.dispose = cleanup; // will be called by 
                            // Microsoft for cleanup
            $(window).bind("unload", cleanup);
    }

    function cleanup() {
            if (!el)
                return;
            $(el).unbind();
            $(window).unbind("unload", cleanup);
            el.dispose = null;
            el = null;
        };
    });
    };
})(jQuery);

function add() {
    $get('res').value = 
        parseInt($get('i1').value) + parseInt($get('i2').value);
}
Sys.Application.add_load(function() {
    $('.num').change(add).Disposable();
});

答案 1 :(得分:0)

请你试试这个改变:

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

<script>
   Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(my_init);
   function my_init() {
       document.getElementById("UpdatePanel1").innerHTML = "";
   }
</script>