Difference between revisions of "Close Without End"

From HashVB
Jump to: navigation, search
 
m
Line 2: Line 2:
  
 
'''Well it's not.'''
 
'''Well it's not.'''
 +
  
 
Using End is like driving into a 6 foot btick wall.  It does no clean-up, nothing, it just ends the app.
 
Using End is like driving into a 6 foot btick wall.  It does no clean-up, nothing, it just ends the app.
  
 
'''Why is this bad?'''
 
'''Why is this bad?'''
 +
 
For one it often causes memory leaks.  As well as this you cannot use it if you're subclassing.
 
For one it often causes memory leaks.  As well as this you cannot use it if you're subclassing.
  
 
'''So what do you do?'''
 
'''So what do you do?'''
 +
 
You loop through the forms and ''Unload'' each one in turn - like this:
 
You loop through the forms and ''Unload'' each one in turn - like this:
  

Revision as of 01:16, 20 October 2005

A common misconception among people new to programming is that it's OK to use the End keyword.

Well it's not.


Using End is like driving into a 6 foot btick wall. It does no clean-up, nothing, it just ends the app.

Why is this bad?

For one it often causes memory leaks. As well as this you cannot use it if you're subclassing.

So what do you do?

You loop through the forms and Unload each one in turn - like this:

 Dim f As Form
 For Each f In Forms
     Unload f
 Next f

Simple as that.