Hao Jiang,
As Göran & Herfried suggests setting myCustomer = Nothing is not needed for
the reason you give.
Instead of calling Dispose outright I would recommend using the new Using
statement in .NET 2.0 (VS 2005). The Using statement ensures that Dispose is
called even if one of the statements contained by the Using throws an
exception.
> Public Sub Foo()
Using myCustomer as New Customer
> ...
End Using
> End Sub
Which is basically the following in .NET 1.x:
Dim myCustomer As New Customer
Try
DoSomething()
Finally
If myCustomer IsNot Nothing Then
myCustomer.Dispose()
End If
End Try
--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley -
http://www.tsbradley.net
"Hao Jiang" <Hao
(E-Mail Removed)> wrote in message
news:4551F173-DAB8-4F74-AE61-(E-Mail Removed)...
> Hi,
>
> I see in many MS example code that looks like this
>
> Public Sub Foo()
> dim myCustomer as New Customer
> ...
> myCustomer.Dispose()
> myCustomer = Nothing
> End Sub
>
> I'm wondering if setting myCustomer = Nothing is necessary in this case?
> Since myCustomer is a private variable, once it goes out of scope at the
> next
> line, the reference to the object should be released.
>
> Thanks.
>
> Hao