Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8604051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:28:26+00:00 2026-06-12T02:28:26+00:00

Base on the C# specification, 10.13 Destructors When an instance is destructed, the destructors

  • 0

Base on the C# specification, 10.13 Destructors

” When an instance is destructed, the destructors
in that instance’s inheritance chain are called, in order, from most derived to least derived.”

My questions are:

why destructors are called, in order, from most derived to least derived?
why not are called, in order, from least derived to most derived or other order?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:28:27+00:00Added an answer on June 12, 2026 at 2:28 am

    Because objects are built up from the least derived to the most derived, so they have to be torn down from the most derived to the lest derived.

    The deriving class knows about base class, but the base class doesn’t know about the derived class. If you would tear down the object from the least derived class to the most derived class, the base class would remove things that the derived class might need in the process.

    Consider for example that the base class has a list of objects:

    public class MyBase {
    
      public List<SomeObject> list;
    
      public MyBase(){
        list = new List<SomeObject>();
        list.Add(new SomeObject());
        list.Add(new SomeObject());
        list.Add(new SomeObject());
      }
    
      ~MyBase() {
        foreach (SomeObject obj in list) {
          obj.Cleanup();
        }
        list.Clear();
      }
    
    }
    

    The derived class adds something to each item in the list:

    public class MyDerived : MyBase {
    
      public MyDerived() {
        foreach (SomeObject obj in list) {
          obj.SomeProperty = new Handler();
        }
      }
    
      ~MyDerived(){
        foreach (SomeObject obj in list) {
          obj.SomeProperty.Cleanup();
        }
      }
    
    }
    

    When the object is torn down, the derived class needs access to the list in order to clean up what it added. If the base class was destructed first, the derived class wouldn’t have access to the objects in the list.

    (Note however that IDisposable is normally a better option to handle controlled cleanup of objects.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The C# language specification says that if I inherit a class, and the base
My base class has properties that are used by a subclass. where should Release
I'm writing a specification for a toy package I'm writing, and while most of
After debugging a particularly tricky issue in VB.NET involving the order in which instance
I have a webservice with a method that takes a parameter of abstract base
In my experience and that of others (http://webster.cs.ucr.edu/Page_TechDocs/pe.txt), the PE/COFF specification document incorrectly claims
Say you have a legacy website running on an old code-base that offers certain
A file that is given as input to the linker is called Object File
I am confused with the following statement. From the specification: Before the implicitly-declared default
I have quite a complex entity structure where several classes inherit from a base

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.