Microsoft & .NETVisual BasicVB Coding Tip: Unload a Program Releasing All Memory

VB Coding Tip: Unload a Program Releasing All Memory content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

When you first start to program, memory management is not really an issue. But as you build larger and more powerful programs that are going to be used by more people, you will soon realise that your program needs to use the least amount of memory as possible, and, as a must, release it all after if finishes. This tip loops through the forms in your project unloading them. You might also want to consider setting your objects to nothing. E.g. Set db = Nothing

Private Sub Form_Unload(Cancel As Integer) 
Dim intCount As Integer 
While Forms.Count > 1 
'// Find first form besides "me" to unload 
intCount = 0 

While Forms(intCount).Caption = Me.Caption 
intCount = intCount + 1 

Unload Forms(intCount) 

'// Last thing to be done... 
Unload Me 
End Sub 

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Latest Posts

Related Stories