VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

Systems Analysis - System analysis and Design tutorial for Software Engineering

You are here: Visual Basic > Advanced VB6 tutorial > Chapter 10

Releasing an Instance of an Object

It is a good practice to free the memory taken up by an object variable after you no longer need it. You can release the object by setting it to Nothing, as in the line

Set xl = Nothing

where xl is the name of the COM component's object variable.

Detecting Whether a Variable Is Instantiated

If an object variable holds a value of Nothing, then the variable doesn't currently hold an instance of any object. You should check an object variable to see if it holds Nothing before attempting to refer to it in your code with a line such as

If xl Is Nothing Then ...

Although it might seem contorted, you will often see syntax such as the following in applications that use COM component objects:

If Not xl Is Nothing Then
'Do some stuff with the xl object
End If


<< Previous | Contents | Next >>

Home | About Us | Privacy Policy | Contact Us

Copyright © | All Rights Reserved