Foundations — Destructor — RAII principle
Before you can understand the parent note, you need to see every word it leans on. This page builds each one from nothing, in an order where each block rests on the previous.
1. What is an "object"? (a labelled box in memory)

Look at the figure. Memory is one long row of numbered slots (called addresses). An object is just a labelled region of those slots. The parent note keeps saying "when the object dies" — that means this box is being taken back by the computer, and something might need to happen first (like returning a borrowed resource).
Why does the topic need this? Because RAII is entirely about the birth and death of these boxes. If you don't picture the box, "lifetime" is a meaningless word.
2. Lifetime & scope (when the box is born and when it dies)

In the figure, the vertical bar is the program running downward in time. The object a appears at its declaration line and vanishes at the closing brace — that vanishing point is where the destructor fires.
Why the topic needs it: the whole phrase "tie the resource's lifetime to the object's lifetime" is empty until you know a lifetime is a span with a definite start and a definite end.
3. Stack vs heap (two places boxes can live)
The parent note casually says "local (stack) object" and "heap object." These are two different memory neighbourhoods.

In the figure: the stack (mint) is a neat pile of plates — last plate on is the first plate off (we'll name this LIFO in §7). The heap (coral) is a messy pool where you point at a chunk with an arrow (a pointer, §5). The stack cleans itself; the heap does not.
Why the topic needs it: the danger the parent note fixes — forgetting to delete — only exists for the heap. RAII's trick is to put a small stack object in charge of a heap chunk, so the self-cleaning stack drags the heap chunk down with it.
4. new and delete — grab and hand back
Why the topic needs it: new in the constructor and delete in the destructor are literally the two halves of an RAII wrapper. Everything else is bookkeeping around this pair.
5. Pointers and the *, &, -> symbols (the arrows)
The parent note writes int* p, *p, a.data, p->x, Base* p. These arrow-symbols are the biggest hurdle, so we build each one.
| Symbol | Plain words | Picture |
|---|---|---|
int* p |
p holds the address of an int |
an arrow, not yet aimed |
&x |
"the address of x" |
grab the arrow that points at box x |
*p |
"the box p points at" |
follow the arrow to the box |
p->m |
"member m of the box p points at" |
follow arrow, then read field m |
p[i] |
"the i-th box after where p points" |
walk i steps along a row of boxes |

The figure shows a pointer p (an arrow) aimed at the first cell of a heap array; p[0], p[1], p[2] are the cells you reach by stepping along.
Why the topic needs it: "the owned resource" in an RAII class is always reached through a pointer. Owning means "I am the one arrow responsible for calling delete."
6. Member functions, constructor, ~destructor (the greeting and goodbye)
Why the topic needs it: this pair is RAII. The whole principle is "constructor grabs, destructor drops, compiler guarantees both fire."
7. LIFO — Last In, First Out (the destruction order)
Picture the stack figure (§3) again: plates come off top-down. So if you build a then b, the death order is b then a.
8. virtual — one word previewed
The parent note's third example needs virtual. Full treatment lives in Virtual Functions & Polymorphism, but the seed idea:
Why the topic needs it: the parent's Example 3 is exactly this trap. You need the word before that example makes sense.
Prerequisite map
Equipment checklist
What is an object, in one picture?
What is a scope, and how is it marked in C++?
{ ... }; a name lives from its declaration to the matching }.What is a lifetime, and why is it "deterministic" in C++?
} or delete), not "sometime later."Difference between the stack and the heap?
new and must hand back with delete.What do new and delete[] do?
new int[100] acquires heap room and returns an arrow to it; delete[] hands that whole block back.What is a memory leak?
new but never released with delete, so it stays reserved forever.What is a pointer, and what do *p, &x, p->m, p[i] mean?
*p = the box it points at, &x = address of x, p->m = member m of that box, p[i] = the i-th box along.Why is a shallow copy of a pointer dangerous?
delete on it → double delete / crash.What is a constructor vs a destructor?
~Class() runs automatically at death to release/clean up.What are the three fixed rules about a destructor?
What does LIFO mean and why is it the destruction order?
What does a virtual destructor guarantee?
Connections
- Parent: Destructor — RAII principle
- Constructor — initialization
- Rule of Three / Five / Zero
- Smart Pointers — unique_ptr & shared_ptr
- Exception Safety & Stack Unwinding
- Virtual Functions & Polymorphism
- Move Semantics
- std::lock_guard & scope guards