473,805 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

When should objects be closed and/or variables cleared?

MS
When is it appropriate to "close" objects?

Example. Which of these objects should be "closed"?

Dim Wsp as Workspace
Dim Dbf as DataBase
Dim Rstb as Recordset
Dim Tdf As TableDef
Dim Cdb As DataBase

Set Wsp = DBEngine.Worksp aces(0)
Set Dbf = Wsp.OpenDatabas e(path & "DatabaseName.m db")
Set Rstb = Dbf.OpenRecords et("TblInfo", dbOpenDynaset)
Set Cdb = CurrentDb

Normally, I just "close" the database object like this.....

Set Dbf = Nothing or Set Cdb = Nothing

Is that sufficient? Is it the correct way?

Is it the same as this?
Dbf.close

Should I be setting them all to "nothing"?
Set Wsp = Nothing
Set Rstb = Nothing
Set Dbf = Nothing
Set Cdb = Nothing
Set Tdf = Nothing

Should they all be "closed"?
Wsp.Close
Rstb.Close
Dbf.Close
Cdb.Close
Tdf .Close

By not setting them all to nothing, or by not "closing" them all, am I
wasting memory?
Thanks for any help!
Nov 13 '05 #1
1 1546
In General - If you Open in, then Close it ... If you Set = Something, then
Set = Nothing

So you would
Set Wsp = Nothing
dbf.Close
Set dbf = Nothing
rstb.Close
Set rstb = Nothing
Set tdf = Nothing
Set cbd = Nothing

FWIW, most "cleanup" code you see simply sets object vars = Nothing. From
what I've been able to gather from newsgroup postings, Closing object
variables was much more critical in 97 than in later versions of Access. I
could be misled about this, howver, and I've always just followed the old
advice at the top of this post ... if I open it, I close it and if I Set it,
I Set=Nothing.

"MS" <Em***@Myemail. com> wrote in message
news:gd******** ********@news-server.bigpond. net.au...
When is it appropriate to "close" objects?

Example. Which of these objects should be "closed"?

Dim Wsp as Workspace
Dim Dbf as DataBase
Dim Rstb as Recordset
Dim Tdf As TableDef
Dim Cdb As DataBase

Set Wsp = DBEngine.Worksp aces(0)
Set Dbf = Wsp.OpenDatabas e(path & "DatabaseName.m db")
Set Rstb = Dbf.OpenRecords et("TblInfo", dbOpenDynaset)
Set Cdb = CurrentDb

Normally, I just "close" the database object like this.....

Set Dbf = Nothing or Set Cdb = Nothing

Is that sufficient? Is it the correct way?

Is it the same as this?
Dbf.close

Should I be setting them all to "nothing"?
Set Wsp = Nothing
Set Rstb = Nothing
Set Dbf = Nothing
Set Cdb = Nothing
Set Tdf = Nothing

Should they all be "closed"?
Wsp.Close
Rstb.Close
Dbf.Close
Cdb.Close
Tdf .Close

By not setting them all to nothing, or by not "closing" them all, am I
wasting memory?
Thanks for any help!

Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2299
by: gogogo_1001 | last post by:
Dear all, I don't understand why "delete" works well on destructing a object, but fails to destruct a vector of it. Any of your comment is highly appreciated! Following is the program that represent this problem:
2
5534
by: Michael Søndergaard | last post by:
I can't seem to figure this one out. I have a list of objects containing objects like A, B, C. I also have another object D which referer object A. At some point in my code I need to delete the reference to object A in obj D, so I do this D.A = null; The question is does this only delete the reference to A or does it also delete the object by invoking the destructor of object A. Or am I saved by the fact, that a reference still exists...
13
4342
by: Joner | last post by:
Hello, I'm having trouble with a little programme of mine where I connect to an access database. It seems to connect fine, and disconnect fine, but then after it won't reconnect, I get the error "operation is not allowed when object is open" so I take out the line of code: BookDetails.Connection1.Open and it comes up with the error "operation is not allowed when object
4
3720
by: Keith H. | last post by:
I found a post on this problem from 2004, but no one at that time replied to it- I'm hoping to have better luck than the original author! As the subject states, I'm running into a problem where the msaccess.exe process does not end once a user exits a database. The author referred to a possible connection to conditional formatting, and I do use that feature a lot. Any help would be appreciated...thanks!
13
1941
by: Adam Right | last post by:
Hi, I am developing a financial application and you know that there are huge amount of data in these similar aplications. I have a MDIChild form and the other forms are opened in this form. For example, in a form i fetch many rows from the database to show them to the user on the client machine. After this process memory gets higher but when the user closes that form the memory remains same amount. I am using IDisposable interface for...
11
3030
by: Huayang Xia | last post by:
What will the following piece of code print? (10 or 15) def testClosure(maxIndex) : def closureTest(): return maxIndex maxIndex += 5 return closureTest()
58
4698
by: Jorge Peixoto de Morais Neto | last post by:
I was reading the code of FFmpeg and it seems that they use malloc just too much. The problems and dangers of malloc are widely known. Malloc also has some overhead (although I don't know what is the overhead of automatic variable sized arrays, I suspect it is smaller than that of malloc), although I'm not too worried about it. I was thinking that, with C99's variable length arrays, malloc shouldn't be needed most of the time. But I'm...
5
5897
by: Tony | last post by:
I am continuing to develop an Access 2007 application which was originally converted from Access 2003. In Access 2003 I was able to disable the Access Close button in the top righthand corner of the screen. I have been unable to find any way to disable this button in Access 2007 and subsequently I have been forced to find ways to detect and handle the situations after the Access Close button has been clicked. I have been largely...
1
1842
by: Ramchandar | last post by:
Hi, I have an ASP.Net web application hosted in my local server with IIS 5.0 as web server. This worked fine with no issues. So I tried hosting the same into the server machine where I have IIS 6.0 as web server. I am having an issue : Onclick of the submit button the session variables are getting cleared. I don’t know why it is happening. I am not able to find why and where the session variables are getting cleared. Is there any setting...
0
9718
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10613
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.