Ok, I think this a little more complicated. I have two lists both
referencing the same collection of objects. The two lists simply provide
different traversal paths for the objects. For example, one may be an
alphabetic listing and the other a numeric listing. How would I load each
list (givent that each list has it's own method for sorting) without
actually instantiating multiple instances of the objects?
Dim List1 as New ArrayList()
Dim List2 as New ArrayList()
Dim A as MyObject()
Dim i as Integer
for i = 0 to 10
A = New MyObject()
List1.Add(A)
List2.Add(A)
next
In this case if I access A from one list, will the changes I make to A be
recognized by the same instance of A in the second list? Also, if I set a
reference to A in List1 to nothing, will the reference to the same instance
of A in the second list be invalid?
I guess my real question is does VB handle a reference count automatically
on instances of objects?
"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
"Scott Cupstid" <sc******@tampabay.rr.comschrieb:
>Ok, here it is. Which is more correct?
AList = New ArrayList
for i = 0 to 10
A = New myObject
AList.Add(A)
A = nothing
next
--- OR ---
AList = New ArrayList
for i = 0 to 10
A = New myObject
AList.Add(A)
next
You do not need to set 'A' to 'Nothing' if it is a local variable. I'd
write:
\\\
Dim AList As New ArrayList()
For i As Integer = 0 To 10
AList.Add(New MyObject())
Next i
///
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>