Debug Foundry

Watch C++ memory free itself, owner by owner.

Turn it, pause it, drag through the steps. Then flip the ownership style and watch the ending change.

Not a video. A small simulation of who frees what — the scope on the left, the heap on the right.

Drag to turn · scroll or pinch to zoom

Finished state of the smart pointers simulation

Blocks alive
0

1/8First step sentence

    0.0s
    Replay the ending with
    Two blocks pointing at each other

    What it's for

    Good to know

    unique_ptr costs nothing extra — same size, same speed as a raw pointer. shared_ptr keeps a small count next to the block and updates it atomically; that bookkeeping is its price.

    How it works, step by step

      Why each step follows

      Before you rely on it

      This is a model of ownership, not of your compiler: real destructors, RAII timing and shared_ptr's control block are simplified away. The leak, the dangle, the automatic free and the cycle are exactly as shown.

      Reference