VB.NET tutorial: Clean up objects


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 Sub Dic_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
'clear objects
cn = Nothing
com = Nothing
ad = Nothing
reader = Nothing
End Sub

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 Sub CloseToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseToolStripMenuItem1.Click
End Sub

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.


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.