Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do you need to "unwire" event handlers in ASP.NET webforms

Given that all controls in a WebForm are destroyed (by my understanding) at the end of each postback do you need to "unwire" any event handlers you may have wired up? (Assuming you want to stop handling the events and allow 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; 
    }
}
like image 854
Maxim Gershkovich Avatar asked Jun 20 '11 19:06

Maxim Gershkovich


2 Answers

Unlikely. Your WebForm1 instance's lifetime ends just after the Unload event, if I recall correctly. It's not as though there is a continuing reference to your WebForm1 class after the page is served and cleanup is done.

like image 50
Andrew Avatar answered Sep 22 '22 15:09

Andrew


No, you don't have to. They will be garbage collected.

like image 33
ulrichb Avatar answered Sep 25 '22 15:09

ulrichb