473,396 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.Workspaces(0)
Set Dbf = Wsp.OpenDatabase(path & "DatabaseName.mdb")
Set Rstb = Dbf.OpenRecordset("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 1525
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.Workspaces(0)
Set Dbf = Wsp.OpenDatabase(path & "DatabaseName.mdb")
Set Rstb = Dbf.OpenRecordset("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
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...
2
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...
13
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...
4
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...
13
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...
11
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
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...
5
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...
1
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.