Why using .Close AND =Nothing?

  • Thread starter Thread starter JB
  • Start date Start date
J

JB

In various examples I have seen people using both .Close AND =Nothing

This is from the help in Access 2002:
"An alternative to the Close method is to set the value of an object
variable to Nothing (Set dbsTemp = Nothing)."

Should I use one of them or are both necesarry?
I just want to kill my object.
 
JB said:
In various examples I have seen people using both .Close AND =Nothing

This is from the help in Access 2002:
"An alternative to the Close method is to set the value of an object
variable to Nothing (Set dbsTemp = Nothing)."

Should I use one of them or are both necesarry?
I just want to kill my object.

Many of us use both because, after being burned in earlier releases, we
don't completely trust the object management and garbage collection
routines. So we explicitly close objects we've opened to make sure the
object takes care of the necessary processing, and we explicitly destroy
the reference by setting the object variable = Nothing, to make sure
that Access/VB doesn't accidentally maintain a reference to the closed
object, keeping it from being destroyed.

We shouldn't have to do this, if all the support routines are doing
their jobs. Maybe they are, these days. But time was when they
weren't.

Note: you do *not* want to close an object you didn't open, though you
should destroy the reference you got to it when you're through using it.
 
Back
Top