Results 1 to 5 of 5

Thread: Freeing dynamically allocated memory (RESOLVED)

  1. #1

    Thread Starter
    Hyperactive Member divined's Avatar
    Join Date
    Aug 2004
    Location
    Thessaloniki, Greece
    Posts
    447

    Resolved 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!

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  3. #3

    Thread Starter
    Hyperactive Member divined's Avatar
    Join Date
    Aug 2004
    Location
    Thessaloniki, Greece
    Posts
    447

    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.
    SteadFast!

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Freeing dynamically allocated memory (RESOLVED)

    Quote 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
  •  



Click Here to Expand Forum to Full Width