I know that every new which i use cause i use the memory, so i have to free it up manually or wait until GC clean it up.
suppose i have created the connection to the sql database
SqlConnection myConnection;
which is Global and it is used in
private void Page_Load(object sender, System.EventArgs e)
{
String ConnInfo=ConfigurationSettings.AppSettings["ConnInfo"];
myConnection=new SqlConnection(ConnInfo);
if (!Page.IsPostBack)
BindPage();
}
so i want to close the myConnection in the Page_Unload
private void Page_Unload(object sender, System.EventArgs e)
{
myConnection.Close();
}
but when i debugged the page i couldn't trace that by unloading the page the Page_Unload is running
so i went through the code i found there is line for Page_load in InitializeComponent,so i added this in it also
this.Unload +=new System.EventHandler(this.Page_Unload);
but again it doesn't enter the Page_Unload
is there anything wrong with it?
suppose i have created the connection to the sql database
SqlConnection myConnection;
which is Global and it is used in
private void Page_Load(object sender, System.EventArgs e)
{
String ConnInfo=ConfigurationSettings.AppSettings["ConnInfo"];
myConnection=new SqlConnection(ConnInfo);
if (!Page.IsPostBack)
BindPage();
}
so i want to close the myConnection in the Page_Unload
private void Page_Unload(object sender, System.EventArgs e)
{
myConnection.Close();
}
but when i debugged the page i couldn't trace that by unloading the page the Page_Unload is running
so i went through the code i found there is line for Page_load in InitializeComponent,so i added this in it also
this.Unload +=new System.EventHandler(this.Page_Unload);
but again it doesn't enter the Page_Unload
is there anything wrong with it?