Re: Is setting to Nothing really necessary if procedure is about to end?
- From: "David W. Fenton" <XXXusenet@xxxxxxxxxxxxxxxxxxx>
- Date: Sat, 20 May 2006 12:54:21 -0500
"Allen Browne" <AllenBrowne@xxxxxxxxxxxxxx> wrote in
news:446f433d$0$31515$5a62ac22@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:
In Access 97, there were 2 bugs that meant you could not close the
database. When you tried, it would minimize to the task bar, but
not close. You had to use Ctrl+Alt+Del to shut it down.
Ultimately, the 2 bugs were tracked down to:
a) referring to a boolean control (check box, toggle button,
option button) without explicitly specifying its Value property
Actually, that is one of the workarounds, not the source of the
problem.
The source of the problem was an implicitly created by reference
call that couldn't be destroyed. If you surrounded the Boolean
control call with parens to force evaluation, it would solve the
problem, too, because it was causing the value to be used rather
than a reference to the control.
This is actally another instance of the same problem, of references
not being released when code goes out of scope, and is a direct
result of VBA's reliance on reference counting for cleanup of
variables -- implicit references don't always get properly managed
in the code that keeps track of them.
Another example of where it's good to be explicit about this is in
any FOR/EACH loop that uses an object variable, such as:
For Each ctl In Me.Controls
...
Next
Set ctl = Nothing
For Each fld In rs.Fields
...
Next
Set fld = Nothing
And so forth.
I started doing this on MichKa's advice.
Lyle has frequently pointed out that the ADO libraries don't have
this problem with VBA, so you don't need to worry about cleaning up
your ADO object variables. However, were I to use ADO in VBA, I
would clean up, anyway, even though it's strictly speaking
unnecessary, simply because I think it's good practice to write code
that cleans up after itself even when the automated garbage
collection routines work reliably.
--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
.
- References:
- Prev by Date: Re: do i NEED to use .movefirst immediately upon opening a recordset?
- Next by Date: Re: Continous Form Records Ranking
- Previous by thread: Re: Is setting to Nothing really necessary if procedure is about to end?
- Next by thread: Re: Is setting to Nothing really necessary if procedure is about to end?
- Index(es):
Relevant Pages
|