469,927 Members | 1,658 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

Releasing Object Variables

Can you post code, or a reference to a md? or ad? file on a website,
where object variables are not released when they go out of scope and
cause a problem, (but causing a problem is extraneous to this
question), other than these two:
DAO.Database
DAO.Recordset
?

To rephrase:
Can you demonstrate any situation where failure to
SET ObjectVariable = Nothing
causes a problem
other than
SET DB = Nothing
SET RS = Nothing
(RS is a DAO Recordset)
?

My applications are code heavy and my own personal choice is to use VBA
script and SQL script through ADO as preferences to any other method of
working. I do not use DAO explicitly. Over the past several years I
have not (as I remember) released any object variable by setting it to
nothing. TTBOMK this has caused zero problems. Perhaps, this is the
same number that setting object variables to nothing has caused you?

Nov 13 '05 #1
18 3241
Br
lylefair <ly******@yahoo.ca> wrote:
Can you post code, or a reference to a md? or ad? file on a website,
where object variables are not released when they go out of scope and
cause a problem, (but causing a problem is extraneous to this
question), other than these two:
DAO.Database
DAO.Recordset
?

To rephrase:
Can you demonstrate any situation where failure to
SET ObjectVariable = Nothing
causes a problem
other than
SET DB = Nothing
SET RS = Nothing
(RS is a DAO Recordset)
?

My applications are code heavy and my own personal choice is to use
VBA script and SQL script through ADO as preferences to any other
method of working. I do not use DAO explicitly. Over the past several
years I have not (as I remember) released any object variable by
setting it to nothing. TTBOMK this has caused zero problems. Perhaps,
this is the same number that setting object variables to nothing has
caused you?


Better to be safe than sorry eh? Tidy programming is tidy programming :)
--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response
Nov 13 '05 #2
That's why I state that I believe in GOD.
If there really is a GOD, then he/she/it might fry my ass for eternity
if I deny GOD's existence.
With GOD, there are side benefits. One gets to destroy aboriginal
cultures, carry on war and terrorism, burn people at the stake (and
carry on torture in general), sodomize choir boys, prevent birth
control and contribute to the poverty and misery associated with such
prevention, control women and their bodies, prevent marriage of people
who love each other, live well and still feel good about oneself.
What are the side benefits to releasing object variables that don't
have to be released besides being able to impress others with "tidy
programming" and stating that "MOST CDMA regulars recommend ...."?

Nov 13 '05 #3
On 21 Jul 2005 05:54:51 -0700, "lylefair" <ly******@yahoo.ca> wrote:
Can you post code, or a reference to a md? or ad? file on a website,
where object variables are not released when they go out of scope and
cause a problem, (but causing a problem is extraneous to this
question), other than these two:
DAO.Database
DAO.Recordset
?


I can't post you a reference, but I can tell you that I had a serious problem
with that using the VBIDE library. The symptoms occurred for me in Access
2000, but not in 2002.

Nov 13 '05 #4
lylefair wrote:
That's why I state that I believe in GOD.
If there really is a GOD, then he/she/it might fry my ass for eternity
if I deny GOD's existence.
With GOD, there are side benefits. One gets to destroy aboriginal
cultures, carry on war and terrorism, burn people at the stake (and
carry on torture in general), sodomize choir boys, prevent birth
control and contribute to the poverty and misery associated with such
prevention, control women and their bodies, prevent marriage of people
who love each other, live well and still feel good about oneself.
What are the side benefits to releasing object variables that don't
have to be released besides being able to impress others with "tidy
programming" and stating that "MOST CDMA regulars recommend ...."?


I guess for me the fact that not releasing them has never caused you a
problem is not proof than not releasing them will never cause me a problem.
I have heard cases from others where it did and I have seen cases myself in
knock-off test files where Access would do the "minimize but don't close"
trick because I didn't clean up my objects properly. Assuming you are
correct and this only affects DAO objects since I DO use DAO I would have to
adopt a coding style where I explicitly release only "some of the time" and
that leads to mistakes.

When I code in Java or dot-net I don't explicitly tidy up so it's not a
matter of being "religious" about it.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #5
On 21 Jul 2005 05:54:51 -0700, "lylefair" <ly******@yahoo.ca> wrote:
Can you post code, or a reference to a md? or ad? file on a website,
where object variables are not released when they go out of scope and
cause a problem, (but causing a problem is extraneous to this
question), other than these two:
DAO.Database
DAO.Recordset
?

.....

Conversley, I have often had problems with calling excel from access using automation
when I did explicitly set everything to nothing. There have been a number of SP
fixes for different versions here.

Nov 13 '05 #6
Bri


lylefair wrote:
Can you post code, or a reference to a md? or ad? file on a website,
where object variables are not released when they go out of scope and
cause a problem, (but causing a problem is extraneous to this
question), other than these two:
DAO.Database
DAO.Recordset
?

To rephrase:
Can you demonstrate any situation where failure to
SET ObjectVariable = Nothing
causes a problem
other than
SET DB = Nothing
SET RS = Nothing
(RS is a DAO Recordset)
?

My applications are code heavy and my own personal choice is to use VBA
script and SQL script through ADO as preferences to any other method of
working. I do not use DAO explicitly. Over the past several years I
have not (as I remember) released any object variable by setting it to
nothing. TTBOMK this has caused zero problems. Perhaps, this is the
same number that setting object variables to nothing has caused you?


I've had problems with Object variables used for Automation (eg. Word,
Excel, Outlook) and with Form variables. Most of the time the problem is
that Access won't Quit (minimizes only) and has to be killed in Task
Manager. Occasionally, I see crashes (used to be the Blue Screen, now
its the XP Send Info to MS dialog).

DB and RS are guaranteed to cause a problem if not released, the others
don't always fail so they be failing when combined with something else.

--
Bri

Nov 13 '05 #7
"lylefair" <ly******@yahoo.ca> wrote in
news:11**********************@g47g2000cwa.googlegr oups.com:
Can you post code, or a reference to a md? or ad? file on a
website, where object variables are not released when they go out
of scope and cause a problem, (but causing a problem is extraneous
to this question), other than these two:
DAO.Database
DAO.Recordset


I don't know of any. But I follow a principle given my MichKa, whose
judgment I trust, and that is to clean up any object variables that
are SET in code, or implicitly in For/Each statements.

I'm now considering adding WITH statements, but if I do that, the
benefit of a WITH over using an object variable disappears.

I suspect that:

For Each ctl In Me.Controls

is not going to create a problematic implicit reference, whereas
code called from elsewhere:

For Each ctl in Forms!MyForm.Controls

might run the risk of leaving an implicit variable.

Reference counting is inherently flawed as a cleanup method and
there could be any number of reasons why it will fail in some
contexts.

Identifying explicit and implicit object references is, I think, not
a bad thing for helping one fully understand one's own code, so I'm
not upset about the voodoo aspect of it.

The longer I'm involved in computers professionally, the less
rational running computers looks to me. The line that makes my
clients laugh is that I tell them to do whatever to their computer
and then to sacrifice two chickens and sprinkle the blood over the
PC. Sometimes the way these boxes behave really does look like it
was the chicken blood that fixed the problem.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #8
foaming@themouth ((another) rude person) wrote in
news:42dfc572.201238065@localhost:
On 21 Jul 2005 05:54:51 -0700, "lylefair" <ly******@yahoo.ca>
wrote:
Can you post code, or a reference to a md? or ad? file on a
website, where object variables are not released when they go out
of scope and cause a problem, (but causing a problem is extraneous
to this question), other than these two:
DAO.Database
DAO.Recordset
?

....

Conversley, I have often had problems with calling excel from
access using automation when I did explicitly set everything to
nothing. There have been a number of SP fixes for different
versions here.


There the problems can be outside of Access. If you set your Excel
application object variable to nothing and don't do a .Quit
beforehand, you'll get an orphaned Excel process hanging out there
taking up memory.

It also illustrates why you should both close and set to Nothing,
because in the case of an outside application, there are two very
different memory structures, one internal and one entirely external
to Access (i.e., the Excel application).

On the other hand, I always felt it was pretty easy to understand
that setting to Nothing did not necessarily release the memory for
the object the variable pointed to. If you have a road sign that
says "New York City 58 miles" taking down the sign does not cause
NYC to cease to exist (however much many might wish it so).

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #9
On Thu, 21 Jul 2005 12:48:57 -0500, "David W. Fenton" <dX********@bway.net.invalid> wrote:
Conversley, I have often had problems with calling excel from
access using automation when I did explicitly set everything to
nothing. There have been a number of SP fixes for different
versions here.


There the problems can be outside of Access. If you set your Excel
application object variable to nothing and don't do a .Quit
beforehand, you'll get an orphaned Excel process hanging out there
taking up memory.


And even if you do everything you should you still get an orphan with some combinations
of Access and Excel, as various KB articles and threads in this group testify to.
I hate "Office automation" as no two users seem to have the same set up.

Nov 13 '05 #10
rkc
lylefair wrote:
That's why I state that I believe in GOD.
If there really is a GOD, then he/she/it might fry my ass for eternity
if I deny GOD's existence.
With GOD, there are side benefits. One gets to destroy aboriginal
cultures, carry on war and terrorism, burn people at the stake (and
carry on torture in general), sodomize choir boys, prevent birth
control and contribute to the poverty and misery associated with such
prevention, control women and their bodies, prevent marriage of people
who love each other, live well and still feel good about oneself.
What are the side benefits to releasing object variables that don't
have to be released besides being able to impress others with "tidy
programming" and stating that "MOST CDMA regulars recommend ...."?


You must be a real scream at parties.
Nov 13 '05 #11
Br
lylefair <ly******@yahoo.ca> wrote:
That's why I state that I believe in GOD.
If there really is a GOD, then he/she/it might fry my ass for eternity
if I deny GOD's existence.
With GOD, there are side benefits. One gets to destroy aboriginal
cultures, carry on war and terrorism, burn people at the stake (and
carry on torture in general), sodomize choir boys, prevent birth
control and contribute to the poverty and misery associated with such
prevention, control women and their bodies, prevent marriage of people
who love each other, live well and still feel good about oneself.
Rather pessamistic view IMO :)
What are the side benefits to releasing object variables that don't
have to be released besides being able to impress others with "tidy
programming" and stating that "MOST CDMA regulars recommend ...."?


--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response
Nov 13 '05 #12
smiling@adversity (polite person) wrote in
news:42dfe5b8.209498112@localhost:
On Thu, 21 Jul 2005 12:48:57 -0500, "David W. Fenton"
<dX********@bway.net.invalid> wrote:
Conversley, I have often had problems with calling excel from
access using automation when I did explicitly set everything to
nothing. There have been a number of SP fixes for different
versions here.


There the problems can be outside of Access. If you set your Excel
application object variable to nothing and don't do a .Quit
beforehand, you'll get an orphaned Excel process hanging out there
taking up memory.


And even if you do everything you should you still get an orphan
with some combinations of Access and Excel, as various KB
articles and threads in this group testify to. I hate "Office
automation" as no two users seem to have the same set up.


I know of plenty of ways to get orphan processes, but I also know of
the right way to avoid it.

If you're getting orphaned processes, then your doing your
automation wrong, seems to me.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #13
rkc wrote:
You must be a real scream at parties.


I'm very good in "Spin The Bottle".

Nov 13 '05 #14

"rkc" <rk*@rochester.yabba.dabba.do.rr.bomb> wrote in message
news:Ya*******************@twister.nyroc.rr.com...
lylefair wrote:
That's why I state that I believe in GOD.
If there really is a GOD, then he/she/it might fry my ass for eternity
if I deny GOD's existence.
With GOD, there are side benefits. One gets to destroy aboriginal
cultures, carry on war and terrorism, burn people at the stake (and
carry on torture in general), sodomize choir boys, prevent birth
control and contribute to the poverty and misery associated with such
prevention, control women and their bodies, prevent marriage of people
who love each other, live well and still feel good about oneself.
What are the side benefits to releasing object variables that don't
have to be released besides being able to impress others with "tidy
programming" and stating that "MOST CDMA regulars recommend ...."?


You must be a real scream at parties.

He's just upset because he was born with low intelligence.

PA
South Carolina

Nov 13 '05 #15
Br
lylefair <ly******@yahoo.ca> wrote:
http://www.triplenine.org


IQ tests aren't always a good indicator of intelligence... and least of
all personality ;)
--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response
Nov 13 '05 #17
On Thu, 21 Jul 2005 19:44:35 -0500, "David W. Fenton" <dX********@bway.net.invalid> wrote:

And even if you do everything you should you still get an orphan
with some combinations of Access and Excel, as various KB
articles and threads in this group testify to. I hate "Office
automation" as no two users seem to have the same set up.


I know of plenty of ways to get orphan processes, but I also know of
the right way to avoid it.

If you're getting orphaned processes, then your doing your
automation wrong, seems to me.

--

Now you are being patronising. I said that some versions will give you errors,
which is true. If you have control of your users machines you can avoid this.
Nov 13 '05 #18
not@all (polite person) wrote in news:42e09f49.257003301@localhost:
On Thu, 21 Jul 2005 19:44:35 -0500, "David W. Fenton"
<dX********@bway.net.invalid> wrote:

And even if you do everything you should you still get an
orphan with some combinations of Access and Excel, as various
KB articles and threads in this group testify to. I hate "Office
automation" as no two users seem to have the same set up.


I know of plenty of ways to get orphan processes, but I also know
of the right way to avoid it.

If you're getting orphaned processes, then your doing your
automation wrong, seems to me.

Now you are being patronising. I said that some versions will give
you errors, which is true. If you have control of your users
machines you can avoid this.


I've never seen it.

Of course, I never use anything but late binding. Perhaps that's why
I've never encountered the problems you're alluding to.

If so, then, we're in a loop.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #19

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by lebo | last post: by
2 posts views Thread by sausage31 | last post: by
2 posts views Thread by M.Ob | last post: by
5 posts views Thread by Mark Rae | last post: by
12 posts views Thread by iker.arizmendi | last post: by
reply views Thread by Matti Airas | last post: by
reply views Thread by 062699 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.