|
-
Apr 25th, 2005, 06:23 AM
#1
Thread Starter
Hyperactive Member
Freeing dynamically allocated memory (RESOLVED)
Hello everybody
When I`m unloading dynamically allocated objetcs in memory I use the statements :
Code:
rsTexnikos.Close
connbio_tech.Close
where rsTexnikos is an ADODB.Recordset object and connbio_tech is an ADODB.Connection object. Do I need to do something else to successfully deallocate the memory? In some source code I was looking at the programmer used :
Code:
rsTexnikos = Nothing
Is this necessary or just a precaution against untimely use of a reference?
thx, in advance
George Papadopoulos
Last edited by divined; Apr 26th, 2005 at 03:00 AM.
SteadFast!
-
Apr 25th, 2005, 06:36 AM
#2
Re: Freeing dynamically allocated memory
From MSDN:
Nothing
The Nothing keyword is used to disassociate an object variable from an actual object. Use the Set statement to assign Nothing to an object variable. For example:
Set MyObject = Nothing
Several object variables can refer to the same actual object. When Nothing is assigned to an object variable, that variable no longer refers to an actual object. When several object variables refer to the same object, memory and system resources associated with the object to which the variables refer are released only after all of them have been set to Nothing, either explicitly using Set, or implicitly after the last object variable set to Nothing goes out of scope.
-
Apr 26th, 2005, 02:58 AM
#3
Thread Starter
Hyperactive Member
Re: Freeing dynamically allocated memory
So, setting a reference to Nothing has effect only when there exist two or more references to an object. But, it doesn`t hurt having it one way or another.
-
Apr 26th, 2005, 03:04 AM
#4
Re: Freeing dynamically allocated memory (RESOLVED)
It has effect when there is only one reference as well. Usually VB will destroy object references and generally clean up itself. But, as you say, it doesn't hurt to use it.
-
Apr 26th, 2005, 05:59 AM
#5
Re: Freeing dynamically allocated memory (RESOLVED)
 Originally Posted by penagate
Usually VB will destroy object references and generally clean up itself.
Unfortunately, you can't trust this to always occur so setting an object to Nothing is more than advisable. IMO - it should be something you get in the habit of doing as second nature.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|