I'll do my best to answer these questions.
1. I don't believe there are eny performance issues with this. There where
issues in VB6, but in .NET, there don't seem to be any issues.
2. b May be slightly more efficient, but you have to decide if you want to
run the possible risk of using the object outside it's intended scope..
3. This seems to have coused alot of discussion in the various newsgroups..
From what I understand, the GC *can* clean up an object even if you don't set
it to Null/Nothing. If the variable is no longer used (i.e. no code using the
variable) then the variable can be garbage collected even if it has not yet
lost scope. Having said that, it does not hurt your code to set it to
Null/Nothing..
4. I don't believe that there are any performance issues with
public/private. Probably more to the point is you should probably keep your
scope as small as possible. i.e If it is needed only internally to a class,
make it private, if it is needed by an external class, make it private with a
public property. Encapsulation is a core concept with OOP development.
Hope this helps a little..
Eddie de Bear
Cheers
"Unruled Boy" wrote:
1.The follow two ways to declare one object: any difference? especially its
performance.
a.Private m_objMyObject As MyObject=New MyObject()
b.Private m_objMyObject As MyObject
m_objMyObject=New MyObject
2.Any difference between a and b?
a.
For Each childItem In SomeItems
Dim objData As DataObject=m_objOneSource.GetData(childItem.ID)
Next
b.
Dim objData As DataObject
For Each childItem In SomeItems
objData=m_objOneSource.GetData(childItem.ID)
Next
3.Explicitly destroy an object will hurt the system performance rather than
improve it?
Dim o_objSomething As SomeObject
'do something
o_objSomething=Nothing
4.Any difference in performance/system resources usage between
public/private declaration of objects/functions?
For example:
a.public objOne as TheObject
b.private objOne as TheObject
--
Regards,
Unruled Boy