473,383 Members | 1,863 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,383 software developers and data experts.

Set the rs variable to nothing when finishing using it

PEB
1,418 Expert 1GB
I don't know is there any effect when i'm finishing to use a recordset from VB
and after
rs.close

i set rs to:

set rs=nothing

Pls explain me what is the effect of set rs=nothing

Is there any economy of memory, or something simillar??

I've tought that rs.close and then mydb.close are enough to close and free the memry for those objects...

Thank you

PEB
Nov 4 '06 #1
6 4382
NeoPa
32,556 Expert Mod 16PB
Every object variable is a link to an object (or it's set to Nothing).
This is particularly important to understand for temporary objects.
When an object var is set to nothing then it will be 'closed' automatically. This is handled by the compiler as differen objects have different meanings for 'Close'.
It is therefore not necessary to close the object explicitly.
However, whan a variable loses scope (a local variable in a procedure, for instance, when the procedure is 'Exit'ed), it is automatically set to nothing intrinsically.
The important thing about Temp objects is that they will remain in existense, only while at least one object variable refers to them. Once the last is set to Nothing, the object disappears.
It's also important to bear in mind, that there are code structures (With TempObj...End With is one that comes to mind) which will keep a link to the object similar to an object variable. In this case the temporary object would also remain until this usage or reference has been released.
Nov 4 '06 #2
PEB
1,418 Expert 1GB
Ok. Thanks NeoPa for this good explication.. In my case i've uset the recordset variable only in functions...

So when the functions finish their work the recordset object varibles that have been used desappear... So in my case there isn't any problem...

In those functions everytime i've used mys.close and mydb.close coz I've setted the database using set mydb=currentDb()

Maybe it's the time to say that if mydb is setted using Workspace and Database a command like mydb.close can close the current database directly...

So i don't need to correct my function writing Set rs= nothing

Thank you NeoPa
:)
Nov 4 '06 #3
NeoPa
32,556 Expert Mod 16PB
I never use a separate variable for CurrentDB - CurrentDB is there, available all the time.
Also CurrentDB won't close with a call like
Expand|Select|Wrap|Line Numbers
  1. Call CurrentDB.Close()
Nov 4 '06 #4
I never use a separate variable for CurrentDB - CurrentDB is there, available all the time.
Also CurrentDB won't close with a call like
Expand|Select|Wrap|Line Numbers
  1. Call CurrentDB.Close()

Your suggestion is good from a pure coding standpoint, but when you consider performance, it may not work.

I tested this back in Access 97, and CurrentDB() calls are slow. I can't remember how slow, but I want to say at least 100 or 200ms. Maybe they've been sped up in latter Access versons? In any case, people should look out for this when using CurrentDB. Other than that, CurrentDB is great.

Jason
May 17 '07 #5
NeoPa
32,556 Expert Mod 16PB
Interesting point Jason.
Would I take that to mean that assigning a db Variable to point to CurrentDB and using that variable in the following code would be a more efficient approach?
Where possible, I always use the With ... construct, which probably saves me from similar type issues in my code.
May 17 '07 #6
NeoPa
32,556 Expert Mod 16PB
FYI This thread was done in my first fortnight as a member here.
Seems like a lifetime ago :D
May 17 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

83
by: Alexander Zatvornitskiy | last post by:
Hello All! I'am novice in python, and I find one very bad thing (from my point of view) in language. There is no keyword or syntax to declare variable, like 'var' in Pascal, or special syntax in...
11
by: doltharz | last post by:
Please Help me i'm doing something i though was to be REALLY EASY but it drives me crazy The complete code is at the end of the email (i mean newsgroup article), i always use Option...
3
by: Defused | last post by:
> i have a file named CDSEncoder.cpp, and i wanted to create a member variable > of this in KNNDlg.cpp...so i wrote the following under my KNNDlg.h file > > protected: > CDSEncoder m_encoder; >...
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
6
by: Steve Jorgensen | last post by:
Many of the regulars here have explained that declaring variables using As New .... is a bad idea, and some have given some good explanations, but I wanted add one more demonstration to the mix. ...
6
by: Mike | last post by:
I have a function that is called when the user clicks the submit button, during this function i also set a varaible to "Y" due to that this function does a post back to the page then redirects....
9
by: Shapper | last post by:
Hello, I am declaring a variable in my aspx.vb code as follows: Public Class catalogue Public productid As String Private Sub Page_Load ... I have an image button where I call the...
6
by: Jody Gelowitz | last post by:
I have run into an issue with variable scope within an XSLT document that is translated in VS.NET 2.0. Under VS.NET 1.1 (XslTransform), this code works fine. However, when using VS.NET 2.0...
11
by: estantep | last post by:
Hello, I am trying to find out an alternate way to brute-force a variable length vector with different variable length contents. int chromossome int max_value_for_each_chromossome
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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...

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.