Cor said:
Branco,
No it does not, the reference has not any more meanings than being a
reference.
(The garbage collector runs by a time, by instance as there is low memory,
it is not a kind of processor occupier).
It should be disposed, but be aware that the method dispose means dispose
unmanaged resources, that has not much to do with disposing an object,
disposing of an object is done by the GC.
Exactly: dispose is a way for the programmer to tell the object: "ok,
I'm done with you, release your resources now and be ready to die when
the garbage collector thinks it's time to get rid of you".
Since the object in point (a control) does implement IDispose (lemme
check... yes, it does [1]) and *may* be holding to an unknown number
of resources, it's fair to call Dispose on the object when the OP is
done with it (which is implied to when the object is set to nothing in
the OP's code).
NOw, setting the object to Nothing has other implications as well:
since the object is declared at class level (where it is declared
"WithEvents"), then, not seting the object to Nothing means that --
even though it has been disposed -- a live reference to it is still
active at class level, but the object being referenced is half dead
and in an unpredictable state. Not only that, it won't be collected by
the GC if the need arises, because there will be a class level
reference to it still active and the GC won't touch that. Therefore
the correct sequence of actions should be, in my opinion (quoting the
original message):
[Co wrote:]
Private Sub CloseUpDTP(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles m_picker.CloseUp
Me.Controls.Remove(m_picker)
'remove references of m_picker from wherever
'else it was added to. and then:
m_Picker.Dispose
m_picker = Nothing
End Sub
Note, however, that in the original code the OP is not calling
Dispose, but is (correctly) assigning Nothing to the variable. Even
though Dispose wasn't called, at least the references for the object
were freed, which means that the garbage collector will address that
object if more memory is needed (and dispose will be called then,
automatically). So, assigning Nothing to the variable *has* a meaning,
after all, despite the fact that Dispose wasn't called (even though it
should).
[Cor Lightert]
You be right, that as the class which is used is not made by using by
instance a component or a form template, then the implementation of Idispose
should be done as well.
HOnestly, I can't get exactly what you are implying. What are you
trying to say? That I'd be right if the object the OP is using was a
component? (well, it is, so I'm right); but then, again, Who is
talking about implementing IDIsposable? The component the OP is using
implements that, so Dispose should be called on it. And since the
variable is at class level, Nothing *must* be assigned to it after
dispose was called.
(Don't get the idea that solely using the dispose
(unmanaged resources) method is implementing that as often is written in
forums or newsgroups.)
<snip>
Sorry I couldn't understand what you're trying to say. Have you
considered using a translator? Maybe you get better results at
expressing what you are trying to.
Regards,
Branco.
[1]
http://msdn.microsoft.com/en-us/library/system.windows.forms.datetimepicker_members.aspx