Destructors

S

swarup

Hi,
Can any body pls tell me in what order the destructors will execute.
I'm having two classes and the object is of the derived class.
 
N

Nicholas Paldino [.NET/C# MVP]

swarup,

You can't determine when finalizers will be executed. They are not
guaranteed to execute when the reference goes out of scope.
 
G

Guest

Hi swarup,
are you worried about which finalizer run first, the one in the derived
class or the one in it's base class? In C# the derived class finalizer will
execute first and then the base classes finalizer is called implicitly, so it
will not be called until the derived classes finalizer has run.

If you mean can you determine which objects finalizer is called before
another object then like Nicholas said this is not deterministic. You should
not be accessing any of the fields inside your class which refer to mananged
resources since you do not know if those resources have already been garbaged
collected or not.

What are you trying to do? If you are worrying about this, then you
probably have some design issue with your code.

Mark.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top