/ˈmɛməri ˈmænɪdʒmənt/

noun … “Organizing, allocating, and reclaiming memory.”

Memory Management is the process by which a computing system controls the allocation, usage, and reclamation of memory. It ensures that programs receive the memory they require while optimizing performance, preventing leaks, and avoiding conflicts. Effective memory management balances speed, space, and safety, and is implemented via operating system services, language runtimes, and hardware support.

Key characteristics of Memory Management include:

  • Allocation strategies: memory can be allocated statically (compile-time) or dynamically (runtime), including stack and heap allocation.
  • Deallocation: reclaimed memory can be managed manually (e.g., C/C++) or automatically via garbage collection (e.g., Java, Python).
  • Segmentation and paging: modern systems divide memory into fixed or variable-size segments or pages for efficient access and protection.
  • Protection and isolation: memory management enforces access controls, preventing unauthorized access between processes.
  • Fragmentation handling: minimizing wasted space due to fragmented allocation, both internally (within blocks) and externally (between blocks).

Workflow example: In a typical program using dynamic memory:

function create_array(size) {
    array = malloc(size * sizeof(int))  -- Allocate heap memory
    for i in 0..(size-1):
        array[i] = i * 2
    return array
}

function cleanup(array) {
    free(array)  -- Reclaim memory
}

Here, memory is dynamically allocated for the array, used within the program, and then explicitly released to prevent leaks. In garbage-collected languages, the runtime automates reclamation based on reachability.

Conceptually, Memory Management is like a warehouse with limited space: items must be stored efficiently, retrieved quickly, and removed when no longer needed to keep operations smooth and prevent overcrowding.

See Memory, RAM, Heap, Stack, Garbage Collection.