MajP
You've got your good things, and you've got mine.
- Local time
- , 22:45
- Joined
- May 21, 2018
- Messages
- 9,934
No you do not. You do not destroy anything. All you are doing is releasing a pointer. But if this makes you feel better continuing doing it.I thought so. But I usually iterate and destroy all the items before destroying the container object. After all, if we really trusted the garbage collector, we wouldn't even consider destroying the container object...
If you believe that VBA does not have a trusted clean up, I say prove it.
All this discussion about setting objects to Nothing is usually a complete waste of time. What you think you are doing is not really doing anything. You are simply releasing a pointer. You are not triggering "garbage collection" or memory clean up. VBA takes care of that.
There are times to close open connections and there are a few times to set objects to nothing. But you are really better off understanding the exceptions instead of thinking you are doing something by setting everything to nothing. At the most I set objects to nothing 1% of the time, but it is for a specific reason. Some of this is described here.
When Are You Required To Set Objects To Nothing?
learn.microsoft.com
Is Manual Memory Management Necessary in Modern Day Access? When Does Garbage Collection Occur?
Hi all, I was wondering if I could get some of your opinions on whether explicit memory management in VBA code is a good practice / necessary in modern day VBA. Here's my current understanding, please correct me where I'm wrong. When an object, such as a recordset, goes out of scope, that is...
www.access-programmers.co.uk
People find it easier to just set all objects to nothing based on an urban myth, than trying to understand when and why.
You can disagree with this, and again I say prove it. Show some cases where the code fails when not setting something to nothing. I can demonstrate some of those cases.
I the last twenty years of actively posting stuff on forums, I am sure I have posted 100 of thousands of lines of vba code, 1000s of example dbs, 100s of class modules and rarely if ever set an object to nothing. Only once did someone come back and say the code failed. And this case falls into one of those exact cases explained in the article that I should have taken care of. So I guess I should have set about 100 thousand other variables to nothing just to catch this one case.
Last edited: