Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Set <variable>=Nothing necessary?

137 views
Skip to first unread message

Bill Berry

unread,
Feb 19, 1999, 3:00:00 AM2/19/99
to
I want a rule-of-thumb on whether every procedure that uses a local
recordset (or other DAO) object variable needs to have Set <objname>=Nothing
at the end.

I understand that there are many dark corners and details to this issue, but
I'mmainly concerned with the simple scenarios exemplified below:

I'm writing a function (that may be called hundreds of times per day) that
uses a recordset object to look up some data. I'm just returning a string
value from the function, not any objectreferences. All variables in the
procedure are local-to-the-procedure in scope. If one of those variables is
a recordset, will it automatically be "set to Nothing" when it goes out of
scope (i.e. the procedure finishes) or do I have to manually do a
Set<variable>=Nothing ?.

I want to do the right thing to keep memory "clean and tidy", but I don't
want to have (lots of?!) Set <variable>=Nothing statements which are
functionally redundant.

Please help me with the straight scoop on this basic situation. TIA

Bill Berry


vbas...@my-dejanews.com

unread,
Feb 19, 1999, 3:00:00 AM2/19/99
to
I go for the better safe than sorry principle, I always Close/Nothing any and
all object variables explicitly.

Steve

In article <OVRR6fBX#GA.233@upnetnews03>,

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own

Terry Kreft

unread,
Feb 21, 1999, 3:00:00 AM2/21/99
to
Hi Bill,
In theory all objects are set to nothing when they go out of scope, in
practice it doesn't always happen.

IMO, always set to nothing, if you hit the problem where the ROT isn't
cleared properly it's the devils own job finding where it's happening, far
easier in the long run to get in the habit of removing the objects yourself.


Bill Berry wrote in message ...

Michael Kaplan

unread,
Feb 22, 1999, 3:00:00 AM2/22/99
to
Everyone always has trouble with this whole idea, so I try another tack:

"Microsoft has promised that VBA will always free up object variables and
all resources associated with them when they go out of scope, and that
therefore you do not strictly need to do this. Thus, if you trust Microsoft
that much, never bother to close or set to nothing and everything will be
peachy.

If you believe there may be one or more bugs in a feature that Microsoft has
implemented, you may decide it is in your best interest to explicitly close
what you open and always set object variables to nothing, without exception,
just in case one of these bugs would keep Access from being able to close or
would tie up system resources while your app is running. Its up to you."

Maybe people will listen to it this way? :-)

Michael

Terry Kreft <terry...@mps.co.uk> wrote in message
news:7arq84$aae$1...@gate.mps.co.uk...

Keri Hardwick

unread,
Feb 22, 1999, 3:00:00 AM2/22/99
to
My approach is more simplistic: "Doesn't hurt, could help. Might as well."
Keri

Michael Kaplan wrote in message ...

Michael Kaplan

unread,
Feb 22, 1999, 3:00:00 AM2/22/99
to
Yes, but mine has the virtue that no one trusts Microsoft to not have bugs,
so when they understand that they would have to trust them to have no bugs,
they suddenyl go from self-righteously refusing to close stuff to wanting to
do it. :-)

Michael

Keri Hardwick <ke...@sprintmail.com> wrote in message
news:7arthc$8i6$1...@ash.prod.itd.earthlink.net...

Lyle Fairfield

unread,
Feb 22, 1999, 3:00:00 AM2/22/99
to
You convinced me the first time,Michael. Now, I'm getting paranoid ...
worrying about nothings.

--
Lyle

Michael Kaplan <mic...@spamless.trigeminal.com> wrote in message
news:uLgaFdnX#GA.226@upnetnews05...

Abbot Cooper

unread,
Feb 22, 1999, 3:00:00 AM2/22/99
to
Beautiful - this seems to be the perfect answer IMHO. Maybe you can set your
newsreader to automatically respond with this post every time a post with
the words "Set", "Nothing", and "necessary" hits your in box. The repetition
of endless threads on this topic is beginning to wear thin - I don't know
how you have the patience to continue beating it into people! <sigh>


Abbot Cooper
cooper_N...@mediaone.net
(remove "_NoSpam_" from address when sending)

Michael Kaplan wrote in message ...

Rebecca Riordan

unread,
Feb 23, 1999, 3:00:00 AM2/23/99
to
And here I am, wondering how you have the patience to respond to all those
people asking about internet dbs!

- Rebecca

Abbot Cooper <cooper_N...@mediaone.net> wrote in message
news:7asdiv$bce$1...@usenet41.supernews.com...

Terry Kreft

unread,
Feb 23, 1999, 3:00:00 AM2/23/99
to
What on earth are you talking about? Where in my posting do I
"self-rigtheously refuse to close stuff"?

In fact, apart from being twice as verbose as my reply to Bill, where in
essence does your reply to my posting differ?

1) Access/VBA is supposed to clean up Object variables
2) It doesn't always do this
3) It is easier, in the long run, to do this explicitly.


Michael Kaplan wrote in message ...

>Yes, but mine has the virtue that no one trusts Microsoft to not have bugs,
>so when they understand that they would have to trust them to have no bugs,
>they suddenyl go from self-righteously refusing to close stuff to wanting
to
>do it. :-)
>
>Michael
>
>Keri Hardwick <ke...@sprintmail.com> wrote in message
>news:7arthc$8i6$1...@ash.prod.itd.earthlink.net...
>> My approach is more simplistic: "Doesn't hurt, could help. Might as
>well."
>> Keri
>>

>> Michael Kaplan wrote in message ...
>> >Everyone always has trouble with this whole idea, so I try another tack:
>> >
>> >"Microsoft has promised that VBA will always free up object variables
and
>> >all resources associated with them when they go out of scope, and that
>> >therefore you do not strictly need to do this. Thus, if you trust
>Microsoft
>> >that much, never bother to close or set to nothing and everything will
be
>> >peachy.
>> >
>> >If you believe there may be one or more bugs in a feature that Microsoft
>> has
>> >implemented, you may decide it is in your best interest to explicitly
>close
>> >what you open and always set object variables to nothing, without
>> exception,
>> >just in case one of these bugs would keep Access from being able to
close
>> or
>> >would tie up system resources while your app is running. Its up to you."
>> >
>> >Maybe people will listen to it this way? :-)
>> >
>> >Michael
>> >

Dimitri Furman

unread,
Feb 23, 1999, 3:00:00 AM2/23/99
to
Don't worry Lyle. You're all set.

Lyle Fairfield wrote:
>
> You convinced me the first time,Michael. Now, I'm getting paranoid ...
> worrying about nothings.
>
> --
> Lyle
>
> Michael Kaplan <mic...@spamless.trigeminal.com> wrote in message
> news:uLgaFdnX#GA.226@upnetnews05...

Abbot Cooper

unread,
Feb 23, 1999, 3:00:00 AM2/23/99
to
Copy and paste, "sweetie" - copy and paste....


Abbot Cooper
cooper_N...@mediaone.net
(remove "_NoSpam_" from address when sending)

Rebecca Riordan wrote in message <36d2...@news.uk.ibm.net>...

sbo...@advparadigm.com

unread,
Mar 1, 1999, 3:00:00 AM3/1/99
to
Speaking of dark corners .... if you check you memory monitor you will find
that the memory isn't free even after you set the recordset to nothing. I
have a routine (vb6) that creates 2 recordsets then moves data between them.
After running through 1500 records i close both recordsets AND the database
object and set them all to nothing. Memory usage increases without bound.
Eventually it will fill all available system memory and virtual memory. By
this time you can imagine what the performance is like.


In article <OVRR6fBX#GA.233@upnetnews03>,
"Bill Berry" <bill...@email.msn.com> wrote:

> I want a rule-of-thumb on whether every procedure that uses a local
> recordset (or other DAO) object variable needs to have Set <objname>=Nothing
> at the end.
>
> I understand that there are many dark corners and details to this issue, but
> I'mmainly concerned with the simple scenarios exemplified below:
>
> I'm writing a function (that may be called hundreds of times per day) that
> uses a recordset object to look up some data. I'm just returning a string
> value from the function, not any objectreferences. All variables in the
> procedure are local-to-the-procedure in scope. If one of those variables is
> a recordset, will it automatically be "set to Nothing" when it goes out of
> scope (i.e. the procedure finishes) or do I have to manually do a
> Set<variable>=Nothing ?.
>
> I want to do the right thing to keep memory "clean and tidy", but I don't
> want to have (lots of?!) Set <variable>=Nothing statements which are
> functionally redundant.
>
> Please help me with the straight scoop on this basic situation. TIA
>
> Bill Berry
>
>

-----------== Posted via Deja News, The Discussion Network ==----------

0 new messages