Dynamic Memory and RAII
Stack Memory Versus Heap Memory
Any value produced by a program takes up space in memory. The language carves the program's address space up into several divisions, each with different rules f…
Dynamic Allocation with new and delete
Local variables exist only as long as the block that created them. For a value to persist beyond that point, or for the case where the number of objects cannot…
Dynamically Allocated Arrays
An ordinary array has to have a predetermined length at compile time. If the number of elements can only be known at runtime, or you want your array to have a l…
Memory Leaks, Double Deletion, and Use After Free
When you dynamically allocate an object, you have much more control over its lifetime, and this control also happens to create three classic mistakes very few l…
Resource Ownership
When a program takes possession of some resource which the language will not automatically free for you, someone has to take responsibility for freeing it. Owne…
Introduction to RAII
A manual release of a resource only occurs when all paths of the code remember to release the resource. Even one early return, lost error path, or simple omissi…
Why Modern C++ Avoids Manual Memory Management
Important: This lesson uses classes in the code examples which we haven't covered yet, so you can SKIP it until you learn about classes, in the Classes and Obje…