🎁 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

Code Smell
A surface indication in code that usually corresponds to a deeper problem in the system, suggesting the need for refactoring.
Queue
A data structure that follows First-In-First-Out (FIFO) ordering, where elements are added at the rear and removed from the front.
Linked List
A linear data structure where elements are stored in nodes, each containing data and a pointer to the next node in the sequence.
Algorithm
A step-by-step procedure for solving a problem or performing a computation, defined as a finite sequence of instructions.
Immutable Object
An object whose state cannot be modified after creation, providing thread safety and predictable behavior in concurrent systems.
Twelve-Factor App
A methodology of twelve best practices for building modern, scalable, maintainable software-as-a-service applications.
View All Programming Concepts Terms →