headware said:
Do you have to manually release memory allocated by creating a dynamic
array using ReDim? In other words, if I have the following code:
ReDim Test(1000)
For i = 0 To 1000
Test(i) = "test value " & i
Next
Do have I have set Test = Nothing to prevent a memory leak?
No. You did not create Test using the Set keyword did you? That means it
is not considered an object and there is no need to treat it as one. If
you wish to be explicit, use
Erase Test
By the way, you seem to have gotten the idea that failing to set any
object to nothing will invariably lead to a memory leak, and this is
just not the case. With most objects, there is no problem with allowing
the vbscript garbage handler to take care of them when they go out of
scope. Where memory leaks may occur is with objects that are in a state
in which they cannot be immediately de-referenced by the garbage handler
and thus remain in memory. The most well-known culprits for this are ADO
objects that may be unable to be closed before being set to nothing,
perhaps because they may be getting handled in the wrong order: parent
objects before their child objects. It is a good idea to be explicit
with ADO objects.
You may be interested in this bit from the guy at Microsoft who was
responsible for developing a lot of the scripting runtime library:
http://blogs.msdn.com/ericlippert/archive/2004/04/28/122259.aspx