memorycontext
Memory context is a hierarchical memory allocation framework used by certain software systems to group allocations that share a common lifetime. A memory context represents a pool or arena from which memory blocks are allocated. Contexts can be nested; child contexts are allocated from a parent and can be reset or freed independently, allowing bulk deallocation of all memory allocated within a subtree.
In PostgreSQL, memory contexts play a central role in managing memory for queries and backend processes. The
Implementation typically uses a linked list of blocks and bookkeeping fields to track usage, block size, and
Limitations include the need for careful design to avoid dangling pointers in long-lived contexts, and potential
See also: memory arena, region-based allocator, allocator, PostgreSQL MemoryContext API.