..NET doesn't use destructors, it uses Finalizers. The main difference being
that with a destructor, you know when it is going to occur and with
Finalizers you don't.
Because .NET uses Garbage Collection and non-deterministic finalization for
objects stored on the managed heap, you can't know when (or technically
"if") an object will be removed from memory. That is the moment in which
your Finalizer will fire. Instead, you should write any cleanup code you
have in the class's Dispose() method and simply call Dispose when your code
no longer is using the object.
FYI - Decaring your instance with CSharp's "using" statement, causes that
object to automatically call its' Dispose method when the using block is
complete.
-Scott
"Eitan" <Ei***@discussions.microsoft.comwrote in message
news:4C**********************************@microsof t.com...
Hello,
I have a WinForm application I am working on.
The application has one main Form with a few buttons. Pressing each of
the
buttons will open a new Form. On one of these Forms (the one in question,
RunForm) I am instantiating an Object (a class I wrote and named
ChannelComm)
that has a destructor.
This Form in question (RunForm) is started/called in the following way:
RunForm dlg = new RunForm();
DialogResult res = dlg.ShowDialog();
dlg.Dispose();
What I am noticing, using a breakpoint, is that the destructor for
ChannelComm is not called. Why isn't it called?
Thanks,
Eitan Barazani