On Tue, 5 Feb 2008 07:06:01 -0800, Will
[quoted text, click to view] <Will@discussions.microsoft.com> wrote:
>Just curious...
>
>Given:
> Dim cmd As New SqlClient.SqlCommand
> ...
> Dim prm1 As New SqlClient.SqlParameter("@ID",'DOG')
> cmd.Parameters.Add(prm1)
>
>Does
> cmd.Parameters.Clear
>remove the prm1 from memory, or just from the cmd Parameters list?
>
>Should I also perform a
> prm1 = Nothing
Neither "removes prm1 from memory". cmd.Parameters.Clear() removes
any references to prm1 from the cmd.Parameters collection. Once that
has been done and when the variable prm1 no longer references the
parameter object, then the parameter object is available for garbage
collection and will be collected when the memory is needed.
Assuming that the variable prm1 is a local variable and will go out of
scope shortly after the code snippet you show, there is no advantage
to setting prm1 = Nothing since that effectively will happen as soon