Background:
I just came across this question and made me learn about erase statment in arrays.
I have always used the following to reset them:
Sub TestWithRedimOnly()
Dim ExampleArray() As String
ReDim Preserve ExampleArray(1)
ExampleArray(1) = "yo"
MsgBox ExampleArray(1)
ReDim ExampleArray(0) As String
MsgBox ExampleArray(1) 'this confirms is reset!
End Sub
If I do it with erase
Sub TestWithEraseAndRedim()
Dim ExampleArray() As String
ReDim Preserve ExampleArray(1)
ExampleArray(1) = "yo"
MsgBox ExampleArray(1)
Erase ExampleArray
MsgBox ExampleArray(1) 'this confirms is reset!
ReDim ExampleArray(0) As String
MsgBox ExampleArray(1) 'this confirms is reset!
End Sub
At the end, both reset the variable.
Question:
Is it really worthy to use erase statement? Does it prevent memory leaking better than just the Redim.. As..
Are there any cases that you can recall about not doing it like so?