locked
How To Remove memory Leak From Basic UpdatePanel Page? RRS feed

  • Question

  • User-1584251297 posted

    I am a newbie to AJAX and I have been changing some of my exisitng .Net web applications to incorporate AJAX controls and in particular, utilise the partial postback functionality to improve the user's experience. As part of my development process I always test my pages for memory leakage using the Drip (0.5) utility, which in the past has proven to be very useful in pointing out errors in my Javascript. Currently, I have an application to which I have added a couple of UpdatePanels to a page and when I test this page in Drip, I see that there are references to a textbox being left behind. After many futile attempts to find out where the 'bug' is, I have created a very basic page with one UpdatePanel containing a textbox and a button for its trigger. The functionality is simple in that you type in some text, click the button and the text gets converted to upper-case via an asynchronous call to the button's click() method. Testing this page in Drip however, I still find that there are references to the textbox kicking around when the page unloads. I can therefore only assume that I am missing something obvious (e.g. I should be calling a method of something or clearing down a property, etc.) in my code. Can anyone please advise me as to where I am going wrong? (Apologies if this query has been posted before, I did scour the forum first but couldn't find anything that matched). 

    Default.aspx

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" Title="Main Menu" %>

    <%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TagPrefix="asp" %>

    <!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 id="Head1" runat="server">

    <title>Test Leak Page</title>

    </head>

    <body>

    <form id="form1" runat="server" defaultbutton="">

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

    </asp:ScriptManager>

    <div align="center">

    <br /><br /><br />

    <table width="750px" cellpadding="0px" cellspacing="0px" border="0px">

    <tr bgcolor="#DBECD2">

    <td width="220px">&nbsp;</td>

    <td width="320px"><asp:Button ID="btnAdd" runat="server" Text="Change To Upper"

    Width="300px" ToolTip="Change text to upper-case" OnClick="btnAdd_Click" /></td>

    <td width="30px">&nbsp;</td>

    <td width="100px">

    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">

    <ContentTemplate>

    <asp:TextBox ID="txtAddCentre" runat="server" MaxLength="7" TabIndex="1"

    Width="80px"></asp:TextBox>

    </ContentTemplate>

    <Triggers>

    <asp:AsyncPostBackTrigger ControlID="btnAdd" EventName="Click" />

    </Triggers>

    </asp:UpdatePanel>

    </td>

    <td width="80px">&nbsp;</td>

    </tr>

    </table>

    </div>

    </form>

    </body>

    </html>

     

    Default.aspx.cs

    using System.Web;

    using System.Web.Security;

    using System.Web.UI;

    using System.Web.UI.HtmlControls;

    using System.Web.UI.WebControls;

    using System.Web.UI.WebControls.WebParts;

    public partial class Default : System.Web.UI.Page

    {

    protected void Page_Load(object sender, EventArgs e)

    {

     

    }

    protected void btnAdd_Click(object sender, EventArgs e)

    {

    txtAddCentre.Text = txtAddCentre.Text.ToUpper();

    }

    }

     Other Details

     .Net framework 2.0

    AJAX  Version=1.0.61025.0

    Visual Studio Professional 2008

    IIS 5.1

    Windows XP Professional SP2

    When I test the above page in Drip there are no leaks until I have clicked on the button and done an ansynchronous postback, then I see the following (Edited for brevity) in the Drip Window:

    Refs     Node Type   ID

    5          INPUT         txtAddCentre

    So, somehow, somewhere, there are still references to the textbox which are not getting cleared. Any advice would be appreciated.

    Thanks in advance,...

    Saturday, June 14, 2008 7:31 AM

Answers

  • User2066886143 posted

    mrk,

    Interesting.  I downloaded drip and wrote a small app with an update panel and -- seing is believing, isn't it?  Without knowing what drip is doing and -- more importantly -- not really knowing what the script manager is doing in ASP.NET AJAX, it does appear that elements inside an update panel are not disposed.  Then I did what any curious code monkey would do: I started googling.  So far I've only found this discussion of the memory leak, which matches what you are seeing, but didn't use Drip to diagnose it:

    http://www.velocityreviews.com/forums/t519338-p-ajax-scriptmanager-memory-leak.html

    I've posted to Eilon Lipton's blog (he has a suggestion box) to see if he has some insights into this.  Anyways, thanks for pointing this out.  If it's a real problem with either ASP.NET Ajax or IE, it seems to have been overlooked for a long time.  Definitely worth finding out more about.

    James

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 15, 2008 12:02 PM

All replies

  • User2066886143 posted

    mrk,

    You obviously understand the Drip tool better than I, but isn't this as it should be?  After an async postback, the txtAddCentre element is still in the DOM, and you still want it to act as a trigger when you click it again, right?

    Is a second ref to it being created?  If not, I don't think there is any memory leak.  The page DOM has just been left undisturbed, since the DOM doesn't get recreated on every aync postback -- only parts of it.

    James

    Saturday, June 14, 2008 3:32 PM
  • User-1584251297 posted

    James,

    Thanks for the info however the flaw in your argument that I can see is that the textbox is not the trigger, the button is (which is outside the updatepanel) and no references are left around for the button when the page unloads, only the textbox. Agreed, an asynchronous postback will only update part of the page so the DOM will have changed slightly where the updatepanel and its contents have been re-written by the server. In which case, it would seem that when the updatepanel updates, somewhere it is creating further references to its contents (i.e. the textbox) during the process which are not disposed of automatically, which is why I was wondering whether I am missing something simple such as calling a particular method or setting a property to null, etc, to cater for this? I deliberately made this example simple and basic, with only the AJAX framework involved and no other Javascript in order to try and ascertain what's happening but so far, no clues. Any further thoughts would be appreciated.

     M.

    Sunday, June 15, 2008 10:03 AM
  • User2066886143 posted

    mrk,

    Interesting.  I downloaded drip and wrote a small app with an update panel and -- seing is believing, isn't it?  Without knowing what drip is doing and -- more importantly -- not really knowing what the script manager is doing in ASP.NET AJAX, it does appear that elements inside an update panel are not disposed.  Then I did what any curious code monkey would do: I started googling.  So far I've only found this discussion of the memory leak, which matches what you are seeing, but didn't use Drip to diagnose it:

    http://www.velocityreviews.com/forums/t519338-p-ajax-scriptmanager-memory-leak.html

    I've posted to Eilon Lipton's blog (he has a suggestion box) to see if he has some insights into this.  Anyways, thanks for pointing this out.  If it's a real problem with either ASP.NET Ajax or IE, it seems to have been overlooked for a long time.  Definitely worth finding out more about.

    James

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 15, 2008 12:02 PM
  • User-1584251297 posted

    James,

    I'm glad you're seeing it too (means I'm not crazy!). I did some further experimenting this morning: I put the code on my work laptop and ran it through Drip and guess what? No leaks! Comapring configurations with my main PC it would appear that the only difference is that my work laptop is running IE 6. I am wondering whether Drip utilitises some of the IE libraries in which case, it may well be that the cause lies within IE 7, rather than AJAX itself? I'll be interested to hear what Eilon has to say about this, like you said, definitely worth finding out more about this issue.

     

    M.

    Monday, June 16, 2008 4:14 AM