TRT
Sign in

Core · Module 6 · Lesson 3 of 6

Virtual Destructors: Closing a Hierarchy Safely

Destroy derived objects through base pointers without leaks by declaring a virtual destructor, and trace the construction and destruction order it guarantees.

Pro — members onlyAbout 10 minutes

By the end you can

  • Explain why a base needs a virtual destructor
  • Predict destructor order for deletion through a base pointer
  • Apply the virtual destructor rule to polymorphic bases

Builds on Virtual Functions and Dynamic Dispatch.

01 · A question first

You delete a Book through an Item pointer. The Book holds a cover image buffer and a loan history list. If only the Item part is destroyed, where do those members go, and which single declaration makes the full teardown run?

Make a guess before you read on.

02 · The idea

Members only

Unlock the full lesson

This lesson is part of the membership. Join to read it in full, along with every other premium deep dive.

What's inside

  • Start with the missing line
  • How safe teardown works
  • Why the rule is strict
  • What it costs and when to skip it
  • Mistakes that still leak
  • Analogy and a smart handle check
  • Where this is used

03 · Practice

Something wrong with this lesson? Report a problem