Dictionary: Clean up objects

When the form loads many objects such as cn, rs, ad, com,and reader, are also created in the program for uses and these objects occupy spaces in computer memory. When the form is closed these objects should be released from the memory.

private void Dic_FormClosed(object sender,EventArgs e)
{

cn.Close();
cn = null;
com = null;
reader = null;
ad = null;
rs = null;


}

You also need to add code: this.FormClosed+=new FormClosedEventHandler(Dic_FormClosed); to the form load event to make Dic_FormClosed() method callable.

private void Dic_Load(object sender, EventArgs e)
{
myconnect();
this.Resize+= new EventHandler(Dic_Resize);
this.FormClosed += new FormClosedEventHandler(Dic_FormClosed);

}

Another thing we want to talk here is to let the user close the program when his/her clicks on the Close sub menu item form the File menu. This task can be done simply by attaching the following code to the click event of the Close sub menu item:

private void closeToolStripMenuItem_Click(object sender, EventArgs e)
{

Close();

}

Now, let test your program and enjoy with it. If you have any questions regard this sample project, we recommend you to post them in our computer forum found in top menu of every web page.




HTML Comment Box is loading comments...



This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.