heap
The area of memory where a program stores objects whose size or lifetime is not known in advance, typically reclaimed by a garbage collector.
In more detail
Value types held in local variables usually live on the stack instead. Allocating on the heap is cheap, but every object must later be reclaimed, which is why hot code avoids needless allocations. This memory area is unrelated to the heap data structure.
Examples
.NET: reference types live on the managed heap, and boxing a value type allocates there.In Node.js the V8 heap holds every JavaScript object, string and closure; each worker thread and child process has its own.Related terms
- garbage collection — The automatic freeing of memory held by objects that the program can no longer reach.
- reference type — A type whose variables hold a reference, a pointer to an object stored elsewhere, rather than the value itself.
- boxing — Wrapping a value type such as an int in an object on the heap so it can be treated as an object.
- allocation — Reserving memory for a new object on the heap.
- heap space — One of the separate regions V8 divides its heap into, such as new space for young objects and old space for long-lived ones.
- --max-old-space-size — A V8 option, passed to node, that sets the maximum size in megabytes of old space, the largest part of the JavaScript heap.
- min-heap — A heap in which every parent is less than or equal to its children, so the minimum is at the root; a max-heap reverses the order.
Taught in
- The C# Language: Types, Variables, and Flow Control — Modern .NET Core, C# & Enterprise Microservices
- Collections, Generics, and LINQ — Modern .NET Core, C# & Enterprise Microservices
- Records, Pattern Matching, and Modern C# — Modern .NET Core, C# & Enterprise Microservices
- Node.js Process Architecture: Memory & Heap Spaces — Node.js Internals & Backend Services
- Runtime Configuration: CLI Flags & Native --env-file — Node.js Internals & Backend Services
- Buffer Fundamentals: Slab Allocator & V8 Memory — Node.js Internals & Backend Services
- Child Processes: spawn, execFile, fork & IPC — Node.js Internals & Backend Services
- Worker Threads: worker_threads & SharedArrayBuffer — Node.js Internals & Backend Services
- Diagnostic Profiling: CPU Profiler & Heap Snapshots — Node.js Internals & Backend Services