Freeing Dynamic Arrays

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • headware

    Freeing Dynamic Arrays

    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.Dicti onary), 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
  • Bob Barrows [MVP]

    #2
    Re: Freeing Dynamic Arrays

    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.Dicti onary), 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.


    Comment

    • headware

      #3
      Re: Freeing Dynamic Arrays

      On May 12, 2:52 pm, "Bob Barrows [MVP]" <reb01...@NOyah oo.SPAMcom>
      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.Dicti onary), 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!

      Comment

      Working...