🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

Programming Concepts Intermediate

What is Stack vs Heap?

Two memory regions: the stack stores function call data with automatic cleanup, while the heap stores dynamically allocated objects.

The stack is fast, ordered memory that stores local variables, function parameters, and return addresses. It follows LIFO (Last In, First Out) and is automatically managed — memory is freed when functions return.

The heap stores dynamically allocated objects with manual or garbage-collected cleanup. Heap allocation is slower but flexible — objects can live beyond their creating function. Understanding stack vs heap helps optimize performance and prevent memory issues.

Related Terms

Recursion
A programming technique where a function calls itself to solve a problem by breaking it into smaller subproblems.
SOLID Principles
Five design principles for writing maintainable, flexible object-oriented code: Single Responsibility, Open-Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion.
Memoization
An optimization technique that caches function results for given inputs, avoiding redundant computations for repeated calls.
Regex (Regular Expression)
A sequence of characters that defines a search pattern, used for string matching, validation, and text manipulation.
Thread
The smallest unit of execution within a process, allowing concurrent operations to run within a single program.
Big O Notation
A mathematical notation that describes the worst-case performance of an algorithm as input size grows.
View All Programming Concepts Terms →