|
-
Jun 24th, 2009, 04:45 AM
#1
[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
-
Jun 24th, 2009, 04:51 AM
#2
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.
-
Jun 24th, 2009, 04:52 AM
#3
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).
-
Jun 24th, 2009, 11:00 PM
#4
Re: Erase on array of objects
 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. 
 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.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|