Freeing Dynamic Arrays

Discussion in 'ASP General' started by headware, May 12, 2008.

  1. headware

    headware Guest

    Do dynamic arrays declared using ReDim have to be freed? I assume that
    if it's an array of dynamically created objects (e.g.
    Scripting.Dictionary), each one of those objects will have to be set
    to Nothing in a for loop, but what about the array itself? Or what if
    the array is dynamic but it just consists of integers or strings, not
    dynamically allocated objects? Does it have to be set to Nothing?

    Thanks,
    Dave
    headware, May 12, 2008
    #1
    1. Advertising

  2. headware wrote:
    > Do dynamic arrays declared using ReDim have to be freed? I assume that
    > if it's an array of dynamically created objects (e.g.
    > Scripting.Dictionary), each one of those objects will have to be set
    > to Nothing in a for loop,


    Depending on the type of object, even that is not necessary since they
    will be released when they go out of scope. Of course, it doesn't hurt
    to do it. With ADO connections, it's probably a good idea to be explicit
    about closing and destroying them. With Dictionary objects, it's
    probably overkill.

    > but what about the array itself? Or what if
    > the array is dynamic but it just consists of integers or strings, not
    > dynamically allocated objects? Does it have to be set to Nothing?
    >


    Arrays are not objects so they cannot be set to nothing. Many years ago
    i read somewhere that it was a good idea to use Erase to clear arrays
    when done with them, but I have not seen that advice anywhere since.
    Again, it can't hurt.

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
    Bob Barrows [MVP], May 12, 2008
    #2
    1. Advertising

  3. headware

    headware Guest

    On May 12, 2:52 pm, "Bob Barrows [MVP]" <>
    wrote:
    > headware wrote:
    > > Do dynamic arrays declared using ReDim have to be freed? I assume that
    > > if it's an array of dynamically created objects (e.g.
    > > Scripting.Dictionary), each one of those objects will have to be set
    > > to Nothing in a for loop,

    >
    > Depending on the type of object, even that is not necessary since they
    > will be released when they go out of scope. Of course, it doesn't hurt
    > to do it. With ADO connections, it's probably a good idea to be explicit
    > about closing and destroying them. With Dictionary objects, it's
    > probably overkill.
    >
    > > but what about the array itself? Or what if
    > > the array is dynamic but it just consists of integers or strings, not
    > > dynamically allocated objects? Does it have to be set to Nothing?

    >
    > Arrays are not objects so they cannot be set to nothing. Many years ago
    > i read somewhere that it was a good idea to use Erase to clear arrays
    > when done with them, but I have not seen that advice anywhere since.
    > Again, it can't hurt.
    >
    > --
    > Microsoft MVP -- ASP/ASP.NET
    > Please reply to the newsgroup. The email account listed in my From
    > header is my spam trap, so I don't check it very often. You will get a
    > quicker response by posting to the newsgroup.


    Thanks!
    headware, May 14, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. countofquad
    Replies:
    4
    Views:
    365
    countofquad
    Mar 5, 2005
  2. headware

    Freeing Dynamic Arrays

    headware, May 14, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    275
    Peter Bromberg [C# MVP]
    May 14, 2008
  3. Freeing Reallocated arrays

    , Aug 19, 2008, in forum: C Programming
    Replies:
    1
    Views:
    306
    Ian Collins
    Aug 19, 2008
  4. Philipp
    Replies:
    21
    Views:
    1,101
    Philipp
    Jan 20, 2009
  5. headware

    Freeing Dynamic Arrays

    headware, May 14, 2008, in forum: ASP General
    Replies:
    1
    Views:
    102
    Bob Barrows [MVP]
    May 14, 2008
Loading...

Share This Page