Revisiting an old friend: Set oRS = Nothing

B

Bob Barrows [MVP]

I still can't get past this:

The VB/VBA documentation has always stated that COM objects are dereferenced
when they go out of scope. When Eric says: "The script engine will
automatically clear those variables when they go out of scope", he isn't
saying anything that the docs haven't said for the last umpteen years.

Yet bugs have been documented that have been corrected by explicitly
destroying them. A couple people on that blog page talked about the old DAO
Database object bug. Another referred to the intemittent IIS failures that
were corrected by explicit cleanup of ADO connection objects. This tells me
that COM _never behaved the way it was supposed to_. Why am I supposed to
all of a sudden start trusting it to behave correctly just because we have
another OS or another version of IIS? To me the burden of proof is rather
high, and would have to involve explaining how the previous failures
occurred and what's been done to prevent them. Instead we get people like
Eric treating us as if we are idiots who don't understand scope and "how COM
works".

Bob Barrows
 
C

Chris Hohmann

Dave Anderson said:
Variable:
Since the Nothing value is not intrinsic to JScript, setting it to *Nothing*
is nothing more than a value assignment -- no better than setting it to
Math.PI or "Bob" with respect to GC. Ditto for null assignments. Scope loss
is the only trigger for such marking.

From KB164494
http://support.microsoft.com/default.aspx?scid=kb;en-us;164494

"The following script demonstrates the problem. When you set the object
reference to null, the object is marked as available for garbage collection,
but it is not released until the garbage collector runs or the script engine
is destroyed: "

So KB164494 in combination with the JScript GC article seems to uphold my
interpretation:
1. Setting object to null marks the object for GC
2. Variant/string/array slot allocations cause GC set the "collect soon"
flag
3. The above flag is checked on the next statement and if it's set, GC is
run

I'm almost positive we've been done this road before.

Agreed. I infer a "since the last sweep" in that item. And I read "array
slots" to be elements, not whole arrays.

Yes. That's what I get for not cuttting-and-pasting. I don't like it when
the formatting get's carried over.

This may be our sticking point. When I first read "new statement", I thought
"new Operator", which seemed to make sense, given the connection between
objects and the need for GC. But now I'm not sure. The casual format of the
Q&A doesn't exactly make it clear that they meant "another statement"
instead of "new Operator".

I'll defer to you on this one, in which case, your string literal assignment
*may* trigger collection (but only in the rare instance that the flag is
set).



Agreed. No! Disagreed. No! Agreed. Pass!
http://tinyurl.com/39zj4

Sorry, no real player. I'm sure it was funny though.
If not memory leaks, what would we attempt to ascertain by comparing the
two?

We would be attempting to ascertain whether or not explicit dereferencing
has a lower memory utilization footprint that waiting for the object to go
out of scope.

I suppose that depends on accepting your definition of "explicitly
dereferencing" in JScript, but I'll see if I have time to test it.

Yes it does. Although now we have KB164494 supporting my definition. Looking
forward to your findings.
 
M

Michael D. Kersey

Bob said:
I still can't get past this:

The VB/VBA documentation has always stated that COM objects are dereferenced
when they go out of scope. When Eric says: "The script engine will
automatically clear those variables when they go out of scope", he isn't
saying anything that the docs haven't said for the last umpteen years.

Yet bugs have been documented that have been corrected by explicitly
destroying them. A couple people on that blog page talked about the old DAO
Database object bug. Another referred to the intemittent IIS failures that
were corrected by explicit cleanup of ADO connection objects. This tells me
that COM _never behaved the way it was supposed to_. Why am I supposed to
all of a sudden start trusting it to behave correctly just because we have
another OS or another version of IIS? To me the burden of proof is rather
high, and would have to involve explaining how the previous failures
occurred and what's been done to prevent them. Instead we get people like
Eric treating us as if we are idiots who don't understand scope and "how COM
works".

Bob Barrows

An excellent summarization. Such bugs as described in
http://www.4guysfromrolla.com/webtech/060999-2.shtml will keep me
performing such practices as setting objects to Nothing until I write
my last line of code. This I consider a good example of another
metaphor: "defensive programming".

Microsoft has had it's share of so-called "regression bugs"
http://www.sciencedaily.com/encyclopedia/regression_testing
wherein a bug in an older version of software is re-introduced in later
versions (often skipping versions). Such occurrences reinforce the
utility of defensive programming.

IMO the OP (and Eric Lippert) are merely fascinated with their
(apparently) recent discovery of the cargo cult metaphor. But the
metaphor has been in common use on the Internet for years prior to
_their_ discovery of the term, e.g.:
http://groups.google.com/groups?q=c...xm=5&as_maxy=1988&[email protected]&rnum=1

Nonetheless, to use yet another metaphor, just as
"To a child with a hammer, all the world looks like a nail.",
so those children among us who have only recently discovered the term
"cargo cult programming" are wildly eager to share with everyone their
newly-discovered "hammer" and possibly to use it to hammer other
programmers. Lippert and Microsoft in general are newbies to the
Internet however, so we can surely forgive their enthusiasm.

From another perspective, I would maintain that _all_ users of
Microsoft products are _necessarily_ "cargo cult" users because
Microsoft doesn't reveal their source code and we necessarily _cannot_
understand how their systems work. As a result, superstitious practices
abound in the Windows world ("Heck, I dunno; why don't you reboot the
system?").

Indeed, to be intellectually honest, _everyone_ is a "cargo cult"
person, because _everyone_ uses words and tools which they do not
understand (at some level), yet which they trust to work (e.g., I would
be hard-pressed to build an automatic transmission for my car, even
given the scrap steel necessary to make the parts). So we're merely
talking about the _degree_ to which we are "cargo cult" programmers. But
to the best of my knowledge there is no consistent "cargo cult scale"
that we can neasure differences with, and so, at that point the metaphor
ceases to be useful.

Good Luck,
Michael D. Kersey
 
R

Roland Hall

in message
: Instead we get people like Eric treating us as if we are idiots who
: don't understand scope and "how COM works".

I understand scope completely. Open the cabinet, remove the bottle, unscrew
the cap, take a swig, swish, gargle and spit. Simple.
 
R

Roland Hall

in message
: Forgot to Set cuboard = Nothing
: You didnt put it back in

That's what wives are for! *ducks and runs*
 
D

Dave Anderson

Michael said:
An excellent summarization...

Indeed. It is the most persuasive argument I have heard to date on either
side of the issue. On the other hand...

...IMO the OP (and Eric Lippert) are merely fascinated with
their (apparently) recent discovery of the cargo cult metaphor.
But the metaphor has been in common use on the Internet for
years prior to _their_ discovery of the term, e.g.:
[URL replaced with http://tinyurl.com/yvehu ]

I cannot speak for Lippert, but this is certainly not my affliction. And the
dismissiveness of this response is insulting to anyone who believes in
challenging his own assumptions. It discounts the very notion that
revisiting assumptions has any worth at all. And I think that is sad.

...From another perspective, I would maintain that _all_ users
of Microsoft products are _necessarily_ "cargo cult" users
because Microsoft doesn't reveal their source code and we
necessarily _cannot_ understand how their systems work. As a
result, superstitious practices abound in the Windows world
("Heck, I dunno; why don't you reboot the system?").

This more or less** fits within the generalized "group of people making
obeisance to something that it is obvious they do not comprehend"
(http://en.wikipedia.org/wiki/Cargo_cult), but the following does not:

Indeed, to be intellectually honest, _everyone_ is a "cargo
cult" person, because _everyone_ uses words and tools which
they do not understand (at some level), yet which they trust
to work (e.g., I would be hard-pressed to build an automatic
transmission for my car, even given the scrap steel necessary
to make the parts).

I think this stretches the analogy too far. Using tools is not shallow
emulation. Just consider the source of the analogy, and see if it fits a
modern proxy: If a U.S. pullout occurred today in South Korea, do you think
the Koreans would perform ritualistic practices to entice back those
mysterious jets that once flew out of Osan? The populous, after all,
understands little (if anything) about the inner workings of F-16 fighter
jets.

So we're merely talking about the _degree_ to which we are
"cargo cult" programmers. But to the best of my knowledge
there is no consistent "cargo cult scale" that we can neasure
differences with, and so, at that point the metaphor ceases
to be useful.

I disagree with the assertion that we are all cargo cult programmers. I
don't believe the cargo cult analogy applies to those of us who are
comfortable with having been wrong, but uncomfortable with being wrong.
Intellectual curiosity an the will to challenge one's own beliefs count for
something.




**I say more or less because I believe there is a distinction between
"cannot" and "do not". Many of us are quite capable of understanding these
things, but lack the access to (or even interest in) the specifics. That is
not the same as failing to comprehend something, IMO.

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
B

Bob Barrows [MVP]

Bob said:
Instead we get people like Eric treating us as if we are idiots

I do wish to retract this as far as Eric's blog itself is concerned. I had
unfairly lumped him in with some people I had encountered in the past who
DID treat those of us who espoused explicit object creation and destruction
as "idiots". Also, at least one of the respondants to the blog does exhibit
this attitude.

I also want to say that, except for ADO objects, I am not as religious about
this as my prior posts may indicate. I sometimes fail to explicitly destroy
my xml domdocument and fso objects. I guess my thinking on this subject has
undergone some alteration ...

Bob Barrows
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top