Skip to content
yul's blog
Go back

2026 November 14th

The stack and the heap

The stack and the heap

  1. The code segment) the compiled program sits in memory; “read-only”
  2. The bss segment) zero-initialized global and static variables are stored.
  3. The data segment) initialized global and static variables are stored.
  4. The heap) dynamically allocated variables are allocated from.
  5. The call stack) function parameters, local variables, and other function-related information are stored.

Q. Is RAM divided into fixed sections ahead of time? A. No, it’s dynamic. RAM isn’t divided into fixed sections ahead of time. The OS gives memory to programs as they ask for it, so whichever program needs more gets more.

Heap

Stack

Dynamic memory allocation with new and delete

Dynamic memory allocation with new and delete

C++ supports three basic types of memory allocation.

Static & Automatic memory allocation’s limit

Dangling Pointers

Memory Leaks

Destructors

Destructors

Destructor: a special kind of class member function that is executed when an object of that class is destroyed.

RAII

Applying C++ concepts to Metal-cpp

Why does the Renderer destructor call release() on _pCommandQueue and _pDevice ?

Why doesn’t draw() call release() on pCmd , the command buffer?

How is that destructor an example of RAII, which you learned?


Share this post:

Previous Post
2026 November 13th