October 26, 2016
Hot Topics:

VB Coding Tip: Unload a Program Releasing All Memory

  • October 19, 2002
  • By Sam Huggill
  • Send Email »
  • More Articles »

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 

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel