Freeing Dynamic Arrays

H

headware

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
 
B

Bob Barrows [MVP]

headware said:
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.
 
H

headware

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.


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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top