2
In terms of performance, what is more preferable? There are other differences between the two modes than performance?
Reset a variable multiple times?
Private Sub Metodo()
Dim MeuTipo As Tipo
For i As Integer = 0 To 100
MeuTipo = New Tipo
MeuTipo.FacaAlgumaCoisa()
Next
End Sub
Or recreate it multiple times?
Private Sub Metodo()
For i As Integer = 0 To 100
Dim MeuTipo As New Tipo
MeuTipo.FacaAlgumaCoisa()
Next
End Sub
The two forms are bad, because
MeuTipo
could be instantiated once out of thefor
and within it callFacaAlgumaCoisa()
! the two forms create unnecessary instances to each interaction.– novic
I understand. And what is the disadvantage of having unnecessary instances at each iteration?
– vinibrsl
Look in this specific case of the example of the code presented, there is first the need to have an object to each interaction already seen that an Object of the class
MeuTipo
provides the methodFacaAlgumaCoisa()
which is what you need to call in every interaction of the repeat structure. You may even ask me more is there at some point that I can use. Yes, there is an example that I remember now is when we need to create a List of Objects by Example of Meutipo, the first code of yours with an adjustments would give to employ this. In the context it is not necessary only use memory– novic