Skip to content

1.1 The hard triangle: what automatic reclamation costs

Before learning a new language, start with a basic question: in a world that already has C, C++, Java, Python, and Go, why design Rust at all?

The answer lies in its primary goal: achieving both hardware-level performance and memory safety at the same time. For decades, mainstream languages treated those two goals as an either-or choice. Write b = a for an object in Python, Java, or JavaScript, and both variables point to the same object in memory; you write no cleanup code, and the program runs safely because the runtime absorbs the cost of memory management. Write C or C++, and your code runs directly against the hardware, while you shoulder the burden of scheduling deallocation and preventing memory corruption.

To see what Rust is aiming for—and what price it pays to get there—we need to step back to three competing dimensions of language design:

  • Performance: how little overhead the compiled code incurs on hardware.
  • Safety: whether the language prevents memory bugs such as accessing freed memory or reading and writing out of bounds.
  • Expressiveness: both the reach of high-level abstractions and how freely you can write code without structural restrictions.

We call the tension among these three dimensions the hard triangle of programming languages. It is a matter of degree rather than a binary switch—lean heavily toward any two, and you pay a steeper price on the third.

The hard triangle of performance, safety, and expressivenessA triangle whose three vertices are performance, safety, and expressiveness. The left edge joins safety and performance, labeled "who frees, and when"; the right edge joins performance and expressiveness, labeled "the cost of abstraction"; the bottom edge joins safety and expressiveness, labeled "how much control the programmer gets". The center reads "hard to max all three".hard to max all threesafety ↔ performancewho frees, and whenperformance ↔ expressivenessthe cost of abstractionsafety ↔ expressivenesshow much control the programmer getsPerformanceSafetyExpressiveness

This section focuses on the first edge Rust sets out to conquer: safety versus performance—who frees memory, and when.

Safety and performance: who frees memory, and when

Section titled “Safety and performance: who frees memory, and when”

The split along this edge comes down to a single question: at what moment is memory freed, and who makes that call? Established languages fall into two camps:

  • The programmer decides (manual management in C / C++): memory is freed on the exact line where free or delete runs, with zero runtime scanning or counting. Safety pays the price—reading memory after freeing it, or freeing the same block twice, corrupts memory. In C++, RAII and smart pointers automate scope-based cleanup, yet the compiler generally does not verify whether dangling pointers elsewhere keep accessing freed data.
  • The runtime decides (Java / JavaScript / Python / Go): a runtime collector identifies unreachable memory and reclaims it. Java, JavaScript, and Go rely on tracing garbage collection (tracing GC) to scan object reachability in the background; reclamation timing is nondeterministic and can introduce pauses or tail-latency spikes under heavy load. CPython—the standard Python implementation—relies primarily on reference counting, freeing most objects as soon as their count hits zero while delegating reference cycles to a generational collector.

Placed side by side, the trade-off looks like this:

Dimension Runtime reclamation (Java / JavaScript / Python / Go) Manual deallocation (C / C++)
When memory is freed Nondeterministic under tracing GC; mostly immediate under CPython reference counting On the exact line where free or delete executes
What it prioritizes Safety and unrestricted aliasing: share objects freely without coordinating cleanup Runtime performance and deterministic execution
What it costs CPU and memory overhead for scanning or counting, GC pauses, latency jitter Human vigilance to prevent use-after-free, double frees, and memory leaks
Typical production hazards Lower throughput, tail-latency spikes, elevated memory footprint Process crashes, silent data corruption, or steady memory growth from missed frees

The other two edges: abstraction cost and low-level control

Section titled “The other two edges: abstraction cost and low-level control”

The remaining two edges of the hard triangle shape language design as well:

  • Performance versus expressiveness: whether high-level abstractions add work at runtime. Evaluating a + b in Python dispatches on object types at runtime, whereas adding two int values in C compiles straight to a machine addition instruction. High-level abstractions do not inherently cost runtime speed; the cost depends on how much checking and specialization the compiler finishes ahead of time.
  • Safety versus expressiveness: how much low-level authority the programmer is given. The more freely code can manipulate raw addresses, the fewer safety properties a compiler can prove before execution. C lets you cast an arbitrary integer into a pointer and write through it, leaving the compiler unable to tell whether the target address is valid; Java forbids pointer arithmetic and checks array bounds at runtime.

Later parts return to those two edges. Throughout this chapter, we stay focused on one question: when does memory get freed?

Rust’s entry point: automatic reclamation without GC

Section titled “Rust’s entry point: automatic reclamation without GC”

Both mainstream camps accept a compromise: pay GC overhead for safety, or manage free manually for speed and absorb the risk.

Cross “who decides when to free” with “whether a runtime collector is involved,” and four quadrants emerge. Only the bottom-left quadrant delivers automatic reclamation (not manual) alongside zero runtime collector (no GC)—and that is the path Rust takes.

Four quadrants: who frees, and whether a runtime collector is involvedA two-by-two quadrant chart. The top row is "the programmer decides when to free"; the bottom row is "automatic reclamation". The left column is "no GC, no runtime collector"; the right column is "GC, runtime reclamation". Top left lists C free and hand-written delete in C++. Top right is marked "—", an impossible combination. Bottom left reads: the path Rust takes, automatic reclamation without GC. Bottom right lists tracing garbage collection and reference counting.No GCno runtime collectorGCruntime reclamationProgrammerdecidesAutomaticC freehand-written delete in C++—impossibleThe path Rust takesautomatic reclamation · no GCTracing garbage collectionreference counting

Follow that quadrant one step further, and an apparent contradiction surfaces: if the programmer never writes free, and no collector scans or counts references while the program runs, how can the program know when a block of memory is no longer needed or which line should release it?

Because reconciling those two requirements looks impossible at first glance, mainstream languages long treated “automatic memory management” as synonymous with garbage collection. Rust commits to making the bottom-left quadrant work, yet the hard triangle still holds: when neither safety nor performance gives ground, the cost shifts to the third vertex—compile-time constraints on how code can be written.

Without human bookkeeping or a runtime watchdog, how can a compiler pinpoint when to free memory? In the next section, we inspect the two memory regions a running program uses and see where the cleanup problem actually originates.