"Lauren Quantrell" <la*************@hotmail.com> wrote in
news:11**********************@g14g2000cwa.googlegr oups.com:
OK, so I know to:
Dim RS As ADODB.Recordset
Set RS = CurrentProject.Connection.Execute("EXEC " &
"mySPROCname")
'make all sorts of cool stuff happen here...
RS.Close
Set RS = Nothing
and I also:
Dim cmd As ADODB.command
Set cmd = Nothing
Dim prm As ADODB.Parameter
Set prm = Nothing
Dim ctl As Control
Set ctl = Nothing
Dim objCbo As Object
Set objCbo = Nothing
I have always assumed these are necessary, but am I missing
anything?
Lyle says that it's not necessary with ADO, because the memory leaks
between VBA and ADO don't exist as they do between DAO and VBA.
I don't use ADO, so I can't confirm or deny his assertion.
If I *did* use ADO, I think I'd do manual cleanup, anyway, just in
case.
Now, some of those things are neither ADO nor DAO, such as Control
and Object. Object, I"d definitely set to Nothing, since it can be
any number of things and is very likely to be entirely external to
Access (as opposed to DAO and ADO objects, which, while external to
Access are known by Access; i.e., Access is designed to work well
with them).
Control is different, as it's entirely Access. But Michael Kaplan
once advised in this newsgroup that it's potentially possible that
looping through the controls collection could leave an implicit
reference to a control unreleased, so I always do this:
Dim ctl As Control
For Each ctl In Me.Controls
[do whatever]
Next ctl
Set ctl = Nothing
So, whenever I walk a collection using a specific variable type
(tdf, qdf, ctl, etc.) I set it to nothing, because each iteration of
the loop is going to do an implicit SET = operation.
The exception is when I use a generic variable type:
Dim varItem as Variant
For Each varItem In Me!lstMyList.ItemsSelected
[do whatever]
Next varItem
In that case, the variant data type is one that is never SET to a
value, so there is no need for setting it to Nothing, since it can't
hold an implicit object reference.
--
David W. Fenton
http://www.bway.net/~dfenton
dfenton at bway dot net
http://www.bway.net/~dfassoc