Memory Management

Lesson overview

Topics covered: Stack vs heap, malloc/free, preventing leaks.

Memory Management

Stack: automatic memory, cleared when function returns
Heap: manual allocation with malloc() and free()
int *p = (int *)malloc(sizeof(int) * 10);
Always free(p) when done to prevent leaks.

Article author: Arthur Isaev