Memory is where C++ gives you the most control — and the most ways to go wrong. Every object you create lives in the stack or the heap, and knowing which one decides how fast it is created, how long it lives, and who is responsible for cleaning it up. Leaks, dangling pointers, and double deletes all come from losing track of that responsibility.
This module starts with stack vs. heap memory, then looks at object lifetime: how scopes create and destroy stack objects, and how a class whose destructor releases a resource turns that behavior into a safety tool. That idea is RAII (Resource Acquisition Is Initialization), and it is the foundation of everything that follows.
Smart pointers — unique_ptr,
shared_ptr, and weak_ptr — apply RAII to heap memory,
so you rarely need to call delete yourself.
Move semantics then show how to hand resources from one object
to another without expensive copies. Watch the lessons in order, then continue
on to Classes & OOP.
The Cherno compares the two main places an object can live: why stack allocation is so cheap, what new does on the heap, and why you should prefer the stack when you can.
How scopes create and destroy stack objects, the classic mistake of returning a pointer to a local, and how scoped classes use constructors and destructors to manage resources — the idea behind RAII.
The three standard smart pointers, when to use each, how reference counting works, and why make_unique and make_shared are preferred.
Why copying objects is costly, how rvalue references and a move constructor let you transfer ownership instead, and how std::move fits in.