Is Set <variable-name> = Nothing compulsory to relase resources.

arvindn

Registered User.
Local time
Today, 23:27
Joined
Oct 1, 2003
Messages
99
It's a very straight question. Consider the foll. code

Public function sample() as integer
Dim mrst as DAO.Recordset
Set mrst=Currentdb.Openrecordset(.....
.
.
.
sample=1
End Function

Is it compulsory to put the statementset mrst=Nothing before End Function to release resources used up by the recordset or will mrst going out of scope automatically take care of it.

Thanks in advance.
 
It's a very straight question.
It may be a very straight question but not all straight questions have straight answers.

One straight answer would be… no it is not compulsory to deliberately release resources.
Another straight answer would be… if you want your database to survive the test of time it is compulsory to deliberately release resources.

In theory, resources should be automatically released when they go out of scope.
In practice that does not always happen.

This sounds like a hypothetical argument, but in reality the practical replaces the hypothetical.

As a point of reference, the opening paragraph here

Regards,
Chris.
 
Last edited:
Thanks Chris for replying.

I understand from ur reply, that w.r.t. VBA as a prog. lang. atleast theoretically it is not compulsory to use the statement Set mrst=Nothing.

However,


In practice that does not always happen.


Can i have a concrete example w.r.t. VBA for this particular query of mine so that i can safeguard myself further.



As a supplement, i wish to add why i posted this question (for anyone who is interested).

If we have a pointer to a memnory block and the pointer goes out of scope, then the memory block needn't necessarily be shown as having been freed up in some languages. So, I wished to know whether mrst going out of scope without explicitly using set mrst=nothing might not free up the resources used.

Thanks once again.
 
OK, but first up let us both get something sorted out.

You live in India and I live in Australia and we may misconstrue the meanings or local usage of words.

When you type “w.r.t” I understand that to mean “with reference to”
When you say “for this particular query of mine” I understand “for this particular question of mine”.

I am simply trying to be clear, because I am fundamentally lazy, and don’t wish to type the same thing twice.

“Can i have a concrete example w.r.t. VBA”
No not from me. I do not know how to write any code that would prove the necessity to deliberately de-allocate memory usage in VBA.

But I am not the smartest person on this Earth by a long shot; there is always someone smarter. You will find them on the WWW, (World Wide Wed), and their name is “Anybody Smarter”.

“so that i can safeguard myself further”
My suggestion; take control of your situation and deliberately de-allocate memory.

As for the pointer going out of scope, I am reasonably sure that the memory allocation for the “pointer” would be de-allocated but not necessarily the memory that it points too, two entirely different things.

I honestly hope this is not some hypothetical question raised by students as some sort of bet, in which case the answer will remain undefined and all bets are off.

If a teacher raised the question then that teacher would be better placed in the philosophy department and raise questions about “How many angels can fit on the head of a pin?”

My answer is, as “Anybody Smarter” would say, Just do it.

Regards,
Chris.
 
There's a piece of advice to u too.

Maybe it's the Australian way of being polite, but u can be certain that to my understanding, ur tone/manner is not, plus its better to stick to the technical part of discussion (which i and probably other members are more interested in) as much as possible. There are perspectives and contexts which a person may not be able to visualize which another can or has faced.



But I am not the smartest person on this Earth by a long shot; there is always someone smarter. You will find them on the WWW, (World Wide Wed), and their name is “Anybody Smarter”.

I honestly hope this is not some hypothetical question raised by students as some sort of bet, in which case the answer will remain undefined and all bets are off.

If a teacher raised the question then that teacher would be better placed in the philosophy department and raise questions about “How many angels can fit on the head of a pin?”"



As for the technical part of the query, i understand that as u said its better to be explicit and handle it myself and that's all i wanted to know. Thanks anyway.
 
Personally… I could not be bothered.
 
Well, if anyone else has a clear and precise reply alongwith technical facts related to the original question, i would be grateful. For the time being the water is till a bit muddy.;)
 
Nothing techy but personal experience.

When stepping thru code i have noticed that Set anything gets release (from Access), thus unreachable by access. One would expect that it would also clear everything

Try this:

Dim acc As New Access.Application
Set acc = CreateObject("Access.application")
acc.Quit

If you dont include the quit, another running access is left (claiming resources) eventhought the acc object has been released.

Concluding this assuming its also valid for Recordsets and simular sets... i would say that acc.Quit or simularly rs.close and such ARE verry much needed to clear resources. I am unclear as to the Set ...= nothing thing. I include it for safety sake, but have no technical background to cover that....

Once again, this is from personal experience....

Regards
 

Users who are viewing this thread

Back
Top Bottom