You need to "free" ASP.NET web event handlers

Given that all controls in WebForm are destroyed (in my opinion) at the end of each reverse transition, do you need to "free" any event handlers that you may have connected? (Assuming you want to stop event processing and enable GC)

So for example:

public partial class WebForm1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Do I need to remove this handler?
        btnSubmit.ServerClick += btnSubmit_ServerClick; 
    }
}
+5
source share
4 answers

. WebForm1 Unload, . , , , WebForm1.

+3

, . .

+2

- (WebForm) , "" , . "" , , , , . Page_Unload, .

, , , .

:)

0

, WebForm - , .

, @thmsn, ASP.NET WebForms .

, , Page_Init. , , ASP.NET, InProc - 60 . , GC , ( , ).

A quick fix was to free the event handler in Page_Unload - this example shows that the page's lifetime can easily be pulled out of its useful life. I will not use the session here, although it is far from ideal - and I saw similar errors introduced with backlinks from objects with correspondingly longer page life.

0
source

All Articles