Asked by:
Memory leak with UpdatePanel

Question
-
User1581072340 posted
Hi,
Below an example of a simple web form with an UpdatePanel, a Button, a Label, a TextBox, and a RequiredFieldValidator. When clicking the button multiple times I can see the memory usage is growing without ever being released.
<%@ Page Language="C#" %> <!DOCTYPE html> <script runat="server"> protected void Button1_Click(object sender, EventArgs e) { Label1.Text = "Refreshed at " + DateTime.Now; } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head> </head> <body> <form id="form2" runat="server"> <div style="padding-top: 10px"> <asp:ScriptManager ID="ScriptManager2" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <fieldset> <legend>UpdatePanel</legend> <asp:Label ID="Label1" runat="server" Text="Panel created."></asp:Label><br /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /> <asp:TextBox ID="TextBox1" runat="server" Text="abcd"></asp:TextBox> <asp:RequiredFieldValidator ID="X" runat="server" ControlToValidate="TextBox1"></asp:RequiredFieldValidator> </fieldset> </ContentTemplate> </asp:UpdatePanel> </div> </form> </body> </html>
I think the combination UpdatePanel and RequiredFieldValidator is causing the issue. What I found is that the following collections are growing after every postback:
- Sys.WebForms.PageRequestManager._instance._onSubmitStatements
- document.getElementsByTagName('head')[0].childNodesI tried it in several ASP.NET version, including 4.5.2, with and without UnobtrusiveValidationMode. I do have some code to work around this issue, but it feels like a hack.
Can anybody tell me if this is a known issue and if there is a good way to work around this. Thanks in advance.
Ronald
Wednesday, December 3, 2014 8:01 AM
All replies
-
User475983607 posted
Disable view state on the server controls and see if that helps.
Wednesday, December 3, 2014 8:17 AM -
User1581072340 posted
I cannot see any difference with ViewState disabled.
Wednesday, December 3, 2014 8:29 AM -
Sunday, December 7, 2014 11:13 PM
-
User1918509225 posted
Hi Rovale,
I have tested your code in my side with IE 11,When I try to click multiple times the button, the memory didn't grow .
But Here is a link which may give a right direction:
http://www.codeproject.com/Articles/34348/jQuery-Memory-Leak-in-UpdatePanel
Best Regards,
Kevin Shen.
Monday, December 8, 2014 2:26 AM -
User1581072340 posted
Hi Chetan and Kevin,
Thanks for taking the time to reply. To be honest I did not find anything in your links which might point me in the right direction. The out-of-the-box ASP.NET example page I created is leaking memory because, what I see, at least two collections are keeping references, preventing the garbage collector to release memory. To rule jQuery out, I did not put it in the example.
In the large ASP.NET application we maintain this is causing out-of-memory issues if users work in the same page within the application for more than a while.
Regards,
Ronald
Monday, December 8, 2014 3:24 AM -
User1581072340 posted
Small follow-up: when setting compilation debug="false" in the web.config, the document.getElementsByTagName('head')[0].childNodes collection will no longer grow. The Sys.WebForms.PageRequestManager._instance._onSubmitStatements collection is still growing.
Wednesday, December 10, 2014 9:53 AM