[RESOLVED] Erase on array of objects
Since the Erase method is used to erase an array, does it clean up properly if it is an array of objects? Or do I have to iterate through the array and destroy each object separately?
ex:
vb Code:
Option Explicit
Private objMyObject() As MyObject
Private Sub Form_Load()
Dim i As Integer
ReDim objMyObject(1 to 10) As MyObject
For i = 1 To 10
Set objMyObject(i) = New MyObject
Next i
End Sub
Private Sub Form_Unload()
Erase objMyObject
End Sub
Re: Erase on array of objects
I believe Erase is fine, objects are only kept alive whilst they are referenced.
If you want proof insert a debug.print or some such into the objects Terminate event.
Re: Erase on array of objects
Objects have a counter on how many there are, and when the counter reaches zero the object is destroyed. The objects should be properly destroyed when you call Erase, but not all of them get destroyed if there are references to them elsewhere (the internal counter is bigger than 1).
Re: Erase on array of objects
Quote:
Originally Posted by
Milk
I believe Erase is fine, objects are only kept alive whilst they are referenced.
If you want proof insert a debug.print or some such into the objects Terminate event.
Oh yeah, not sure why I didn't think of this. :o
Quote:
Originally Posted by
Merri
Objects have a counter on how many there are, and when the counter reaches zero the object is destroyed. The objects should be properly destroyed when you call Erase, but not all of them get destroyed if there are references to them elsewhere (the internal counter is bigger than 1).
Thanks.