M
Mythran
Group,
Got a quick question that I have asked in the past but still, no answer that I
think is sufficient for the question.
The question I have pertains to the following snippets:
Public Function Fetch() As DataTable
Dim bllObject As BLL.MyObject = New BLL.MyObject
Dim row As Schema.MyDataSet.MyDataRow
Try
' blah.
row = bllObject.Fetch()
Finally
' Cleanup.
bllObject.Dispose()
End Try
Return row
End Function
Compared To:
Public Function Fetch() As DataTable
Dim bllObject As BLL.MyObject = New BLL.MyObject
Dim row As Schema.MyDataSet.MyDataRow
Try
' blah.
row = bllObject.Fetch()
Finally
' Cleanup.
bllObject.Dispose()
bllObject = Nothing
End Try
Return row
End Function
The difference between the two snippets above is the fact that I am specifically
releasing the reference to bllObject by setting it to Nothing. In VB6, this was
important. I know that the garbage collector in .Net is more efficient and we do
not need to set our object references to Nothing, but is it "More" efficient if I
do set it to Nothing when I'm done with it and not let it release automatically
when it goes out of scope?
Basically, if I have a very large routine (that has already been broken down into
smaller routines, this is the largest one of the smaller ones), shouldn't I
release as soon as possible rather than let it hang around until it goes out of
scope?
Also, if I do set object references to Nothing right before they go out of scope
(before containing routine ends), will that be more efficient than the reference
going out of scope?
Thanks for the help, this has been bugging me for awhile
Mythran
Got a quick question that I have asked in the past but still, no answer that I
think is sufficient for the question.
The question I have pertains to the following snippets:
Public Function Fetch() As DataTable
Dim bllObject As BLL.MyObject = New BLL.MyObject
Dim row As Schema.MyDataSet.MyDataRow
Try
' blah.
row = bllObject.Fetch()
Finally
' Cleanup.
bllObject.Dispose()
End Try
Return row
End Function
Compared To:
Public Function Fetch() As DataTable
Dim bllObject As BLL.MyObject = New BLL.MyObject
Dim row As Schema.MyDataSet.MyDataRow
Try
' blah.
row = bllObject.Fetch()
Finally
' Cleanup.
bllObject.Dispose()
bllObject = Nothing
End Try
Return row
End Function
The difference between the two snippets above is the fact that I am specifically
releasing the reference to bllObject by setting it to Nothing. In VB6, this was
important. I know that the garbage collector in .Net is more efficient and we do
not need to set our object references to Nothing, but is it "More" efficient if I
do set it to Nothing when I'm done with it and not let it release automatically
when it goes out of scope?
Basically, if I have a very large routine (that has already been broken down into
smaller routines, this is the largest one of the smaller ones), shouldn't I
release as soon as possible rather than let it hang around until it goes out of
scope?
Also, if I do set object references to Nothing right before they go out of scope
(before containing routine ends), will that be more efficient than the reference
going out of scope?
Thanks for the help, this has been bugging me for awhile
Mythran