Destructors

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • swarup

    Destructors

    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.

  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Destructors

    swarup,

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


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "swarup" <santiswarupjen a@yahoo.co.inwr ote in message
    news:1163047822 .511559.138030@ h54g2000cwb.goo glegroups.com.. .
    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.
    >

    Comment

    • Mark R. Dawson

      #3
      RE: Destructors

      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.
      --



      "swarup" wrote:
      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.
      >
      >

      Comment

      Working...