Set = Nothing (1 Viewer)

kirkm

Registered User.
Local time
Today, 22:52
Joined
Oct 30, 2008
Messages
1,257
When you Set an object how important or necessary is it to make it = Nothing when finished ?
 

June7

AWF VIP
Local time
Today, 01:52
Joined
Mar 9, 2014
Messages
5,425
Last edited:

kirkm

Registered User.
Local time
Today, 22:52
Joined
Oct 30, 2008
Messages
1,257
Thanks June, interesting link. I'm unsure what conclusion to reach other tahn it 'probably doen't matter'.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:52
Joined
Oct 29, 2018
Messages
21,358
Not sure the exact technical reason or if it doesn't apply anymore, but we just learned it from those who taught us before to "close what you opened" or "destroy what you created." Maybe it's not necessary anymore, but I still follow it (or try to anyway).
 
Last edited:

Micron

AWF VIP
Local time
Today, 05:52
Joined
Oct 20, 2018
Messages
3,476
What is to be gained or lost by not doing so?

If you read all of the posts there, it would appear that memory space might not be reclaimed if you do not set to nothing, but that would appear to be rare. How would you know?? What I didn't see mentioned is what happens if a procedure terminates on error, but perhaps "going out of scope" covers this.

You'll often see opinions meant for VB, C, C++, etc. that get applied to other environments when they should not be. One has to be careful that the opinions relate to the application or programming language for which the question is being asked. Considering that, the comments about DAO, and **M$'s ability to surreptitiously inject undesirable behaviors via updates, I will continue to "purchase" all perils insurance by writing a few extra lines. Besides, it will never reflect poorly on me in the eyes of anyone who might follow if they do not hold the same opinion.

** that was not part of the comments at the link. It is my own opinion.
 
Last edited:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 04:52
Joined
Feb 28, 2001
Messages
27,001
Some folks here might not agree with me on all of this. As a matter of good general programming practice, I always try to close what I opened and put back what I took out. However, I acknowledge that it is a matter of long-learned programming habits that DO include skills in other languages and other operating systems. In the Access environment, closure is more important for some things than for others.

When the object is something intimately associated with Access, such as a recordset, the structure for that object is in the virtual memory of the Windows process/task running Access. Whether it is in the process "heap" is open to question because it depends on where and how the object was declared.

Use of the NEW keyword will often mean "heap" but otherwise, a recordset in a Class module's declaration area or in the declaration area of a subroutine will have the life expectancy of the object in which it was declared. So when a subroutine/function exits, the stack and call frame (and all locally declared variables) are reclaimed into the "stack" area. The recordset object is destroyed along with any other supporting memory structures (as their reference counts all drop to 0).

Objects created based on being in a general module's declaration area have longer lifetimes. They cease to exist only when the session closes (task exit, process exit). In this case, failure to close something might interfere with subsequent operations on that same object. I.e. if you are going back to use a Public recordset variable but it was left open from a prior use, you might get an error trying to open it again without closing it first. And sometimes, for longevity or modularity reasons, you DO declare something in a public variable in a general module because you wanted that longevity. Such cases are legit but require you to close what you opened (so you can open it again later).

For locally declared objects, the reclamation of space occurs based on when the defining object goes away, but in either case, when the task exits, EVERYTHING is cleaned up anyway. All memory-resident structures are dissolved, all objects vanish, memory is reclaimed to the system free-page pool.

But there is another class of object - the external application object. There, it is possible (and I have personally seen this) that if you fail to clean up that external object, it will hang around and you will need to use Task Manager to get rid of it. If the object has a file open, that adds another wrinkle because the utility might wish to ask you whether you wanted to save it or not and it might not be able to do that because it's link with the outside world was your session and that session is suddenly gone. I know that Outlook objects are unusually touchy but I've even had to be careful with Word apps.

In the specific case of external apps that get launched, they have a life OUTSIDE the Access object and therefore, while Access is still able to talk to the controlling object variable, it would be good to tell that app to close what it had open and then pull itself back into its hole, or exit, or whatever is needed.

Now, the part that some find just a bit TOO meticulous is that I think it is a good programming practice to ALWAYS close what you open even if it is something that would go away a few lines later when the routine exits. But let me be clear about that: I do this as a belt-and-suspenders kind of guy. AND if I am using a "common" variable among several subroutines, then it isn't going to go away right away. So if I know I am done with it, I always close it or clean it.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 09:52
Joined
Jul 9, 2003
Messages
16,245
This thread reminds me of that video of the people in the waiting room, an alarm goes off and they all stand up! If you ask any of them why they stood up then no one would know, as they had been set up from the beginning by a clever manipulation.

There's a lot of stuff in MS Access like that, as previously mentioned in this thread where ideas and things have come in from all sorts of places.

This is why I do my own experiments to see what happens, or doesn't.

I also appreciate people like Colin (isladog) who dig down in and ferret out some the obscure working of MS Access.

Sent from my Pixel 3a using Tapatalk
 

moke123

AWF VIP
Local time
Today, 05:52
Joined
Jan 11, 2013
Messages
3,852
I also appreciate people like Colin (isladog) who dig down in and ferret out some the obscure working of MS Access.
I often wonder if Colin sleeps.:D
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 09:52
Joined
Sep 12, 2006
Messages
15,614
it also seems to me that reclaiming space might be a bit nebulous.

all these pointers, and data pointed to must be stored on the stack/heap. When you release a pointer, the pointer and the data pointed to may now become available for other processes, but it is possible that fragmentation within the stack/heap may occur, so you could still get leakage even though you dispose of the objects. Or is it smarter than that?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 04:52
Joined
Feb 28, 2001
Messages
27,001
Dave, I am almost certain that many memory-oriented objects on the heap are re-threaded into a memory list or pool, but there are many reasons why that doesn't mean they are immediately re-used. In fact, many things returned to the heap merely stay there, idle until process exit. If you ever see a Windows error message, "Virtual Memory Exceeded" it is because your heap grew too large - in turn, because the reclamation process was not effective.

This next piece will seem like a diversion, but I have method in my madness. Those old enough to remember the USA "Orange Book" on computer security will perhaps remember that in order to reach the "C3" level of security accreditation, it was necessary for Microsoft to implement a TOTAL rewrite of Windows internals. (Thanks, Dave Cutler!) Otherwise, no Microsoft system would have qualified for further Government contracts. MS-DOS 6.2 and Win3 (and Access v2) would not have passed because their handling of memory was EXTREMELY loose.

Windows NT came out so that Microsoft could qualify for the C3 rating and sell to the US Government. Otherwise, we would all be living in a UNIX-based world. These days, "C3" and the other ratings are no longer used, there is a newer standard - and yes, Win XP complied at the time and Win10 is even higher on that compliance scale. The major "new" feature of WinNT was better use of the advanced memory management hardware that was becoming available on Intel systems, which in turn meant that hardware process isolation was now possible. This hardware isolation changed the way the O/S looked at memory.

Back to memory usage issues: There are levels of re-use. Returning a memory chunk to the heap makes it eligible to be repurposed within the same task, but the C3 "process isolation" principle stops it from being used by another task until process exit is finished. Which is why in my discussion I emphasized multiple classes of object reclamation.

Anything built on the process "User" stack gets released back to the stack at sub or function EXIT, which includes EVERY local variable in a function or sub (except those declared as "STATIC"). As part of that release, when the pointers to objects vanish, Access knows it and has "destructors" to release things related to those locally defined object variables. The actual variables go back to the stack. Remember, object variables are pointers to some other structure. Object structures created through those variables go back to the heap, where re-use is possible but not always likely.

The reason I say "re-use is less likely" is because of random object release. When the process is new, memory is smooth and empty. Once things get hot, memory allocations occur and eventually, memory releases occur. But the random nature of those releases will leave memory fragmented if you have two big chunks of released memory but have one more chunk of memory between them that is still active.

ALL objects and variables (and code and anything else you had in the process) are totally reclaimed by process EXIT. Inside of your process/task, memory is used in small chunks - piecemeal, so to speak. But Windows treats memory allocation in units of pages, where a page's size depends on the specific hardware settings, but might easily be as much as 8 KB of contiguous memory aligned on an even address boundary of 8 KB.

At EXIT time, Windows takes over the pages of released memory and adds them to the Free Page list. That list is safe because as part of the process of preparing to re-use the memory by handing it to a different task, Windows wipes it before taking it out of the FPL. If you ever wonder why task startup takes so long, sometimes it includes time required to pre-erase the memory allocated to you (based on object re-use rules).

My comments about external objects relate to the fact that an external object is part of its own process with separate memory. When Access exits, its memory gets wiped - but the memory of the external app object is still in use and can still have its own active objects. Process-separation rules say that you CAN'T touch anything directly in that other process. You have to ASK it (via application object methods) to clean itself.

To look up more about memory-page flow in Windows, look up "Windows Paging Dynamics."
 
Last edited:

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 09:52
Joined
Jul 9, 2003
Messages
16,245
Sorry about the delay responding... I was asleep :D
Asleep!

My wife and myself have had some sort of bug for nearly a month, which just makes you tired all of the time. Never had anything like it before! My son's got it now.

Occurred to me you might have something similar?

Sent from my Pixel 3a using Tapatalk
 

isladogs

MVP / VIP
Local time
Today, 09:52
Joined
Jan 14, 2017
Messages
18,186
LOL. It was a joke ;)
However I have drastically cut both my forum and development time over the past month or so since moving house. Lots to do here and still not connected to Internet (apart from mobile) after four weeks! Now they've cut off my phone line as well in order to fix the internet!
I could write an essay about the incompetence of BT
 

Gasman

Enthusiastic Amateur
Local time
Today, 09:52
Joined
Sep 21, 2011
Messages
14,050
I could write an essay about the incompetence of BT

I dealt with BT in my last job, pure incompetence in most departments. :banghead: Even if you found someone to go the extra mile, they would be thwarted by some other department. I feel your pain.:)
I've been with NTL/Virgin since they offered 1p per minute on the phone line.
They can be a pain if something goes wrong as well, but fortunately that rarely happens. :)
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 09:52
Joined
Jul 9, 2003
Messages
16,245
I could write an essay about the incompetence of BT

I have written such an essay!

Short version:-

My Shop in Reading.

Intermittent loss of internet access.

BT visited 3 times.

Conclusion it was our system.

Solution I moved over to a new internet provider called Bethere.

Be there contacted me, they couldn't make a connection because there was a fault on the line (BTs line)

I contacted BT, NO there isn't a fault on the line.

I contacted Bethere, I said look I don't want to be a ping pong ball in this game with these incompetent people, what do you suggest?

Be there contacted Openreach, BTs own subsidiary and got the problem sorted out!

BT had charged me for terminating the contract early, I got the money back plus £80!

I agree with Gasman, there are some competent helpful people in BT, it's just the overall system and I suspect the management that's at fault.

Sent from my Pixel 3a using Tapatalk
 
Last edited:

isladogs

MVP / VIP
Local time
Today, 09:52
Joined
Jan 14, 2017
Messages
18,186
In my case, BT confirmed mid April my Broadband would be connected on my move date of 30 April. They also claimed it would be superfast even though everyone else in this part of rural Exmoor has slow Internet. Despite the previous owners having an Internet connection they failed to connect the internet claiming unforeseen difficulties. They set a further connection dates for 3 May when an Open Reach guy spent four hours here rewiring the phone connection and testing everything. He stated there was no reason why I couldn't be connected but despite seeking authorisation wasn't allowed to do so. The problem I now know was their systems rather than wiring issues.
Further dates set for 7 May, 17 May. Same excuse of unforeseen difficulties. After making a formal complaint, a case manager was finally assigned yesterday. He stated my phone line needed to be temporarily disconnected so a new broadband order could be authorised. So I now have no phone either.
New connection date set for 30 May! I'll believe it when I see it.... and it certainly won't be superfast.
In the meantime, I'm considering satellite broadband if they fail once again but that has issues as well

Luckily mobile signals here are excellent!
 

Gasman

Enthusiastic Amateur
Local time
Today, 09:52
Joined
Sep 21, 2011
Messages
14,050
In my last job I worked for Company A. Company B was going to take over and I would be transferred to Company B.
BT agreed that the Company A Cloud phone system could be transferred to Company B with a change in requirements in new premises.

The new requirements were signed in Feb 18 and I went on holiday, fully expecting to have a few gremlins to sort out when I came back.

I came back from holiday and the line was not even installed in the new premises. I was present to let the engineer in to install the line in early March. I then used a spare BT router to test the line, nothing. So I called BT. No one had put the broadband on the line.? :(

We finally had broadband and so moved to the new premises in late March. The Cloud account still in the old company name. That eventually got changed in Sept. :)

For the changeover we agreed on a Friday after 3pm as we finished early on the Friday. Twice that was postponed. The first time was because the account manager who was swapping the account over found out his engineer was on holiday on that day?

Seriously, left hand never knows what the right hand is doing.

The only thing I would credit BT doing well, is their Call Guardian software on their phones. Being out of work, that has saved me countless hours not answering scam/ppi calls when waiting to hear from possible agents/employers.

The phone nevers rings unless they pass the call guardian, so I am blisfully unaware of all these calls. :)

When working, I would come home and find about 12 calls on the phone, and not one message on the answering machine.
 

missinglinq

AWF VIP
Local time
Today, 05:52
Joined
Jun 20, 2003
Messages
6,423
...we just learned it from those who taught us before...Maybe it's not necessary anymore...
I see comments about don't use this function because it runs too slow...or don't use this approach because it's a resource hog...and think that it often does, in fact, go back to the days of 128 KB of RAM, with lightning 10 Mhz clocks...and has nothing to do with today's machines and their performances.

Linq ;0)>
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 04:52
Joined
Feb 28, 2001
Messages
27,001
linq, I can remember buying a brand new Intel-486-based desktop that ran MS-DOS 6.2 and Windows 3.1(a) or some similar nomenclature - and it had advanced memory management (for its time) that allowed it to reach a phenomenal 2 Mbyte of RAM. AND... Windows could actually use that much memory by parceling out tasks using a shell environment manager. It was phenomenal because previous machines would top out at 640 KBytes of RAM. These days, 8 GBytes is merely an average or slightly above average machine. The times, they are a changing!
 

missinglinq

AWF VIP
Local time
Today, 05:52
Joined
Jun 20, 2003
Messages
6,423
Indeed they are! My first box (can't even remember the make) had a 20 mb hard drive and DOS...was pre-Windows...by about three years, as I recall!

First project was a relational database for work, written in QuickBasic...and something as simple as adding three months the current date took up about 4 pages of code!!! Adding mouse capability to the db took even more than that!

When I took a class in Visual Basic (which started out as QuickBasic plus an interface progam named, IIRC, Tripod) I was blown away by the DateAdd() function!

Linq ;0)>
 

Users who are viewing this thread

Top Bottom