dcsimg
September 20, 2020
Hot Topics:

VB Coding Tip: Unload a Program Releasing All Memory

  • 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 
Wend 

Unload Forms(intCount) 
Wend 

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





This article was originally published on October 20, 2002

Enterprise Development Update

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


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