Garbage Collection vs Deterministic Memory Regions in AiVM

May 21, 2026 · Todd Henderson

image

Modern managed runtimes such as the JVM, CLR, Mono SGen, Go, and JavaScript engines rely heavily on sophisticated garbage collectors. These systems are optimized for large, long-running shared heaps with highly dynamic allocation patterns.

AiVM is taking a different path.

Rather than building a traditional “fully managed” runtime with increasingly complex concurrent garbage collectors, AiVM is moving toward a model based on:

This document explains both approaches, their tradeoffs, and why AiVM is intentionally choosing a different direction.


Traditional Garbage Collection

The Goal

Traditional garbage collectors attempt to automatically reclaim memory that is no longer reachable by the application.

The runtime tracks references between objects and periodically identifies memory that can be freed.

Most modern systems use some variation of:


Mark-Sweep Collection

The classic tracing collector works in two phases:

  1. Mark all reachable objects
  2. Sweep unreachable objects

Flow Diagram

                ┌────────────────────┐
                │   Heap Objects     │
                └─────────┬──────────┘
                          │
                          ▼
                ┌────────────────────┐
                │ Root Traversal     │
                │ (stack/globals)    │
                └─────────┬──────────┘
                          │
                          ▼
                ┌────────────────────┐
                │ Mark Reachable     │
                │ Objects            │
                └─────────┬──────────┘
                          │
                          ▼
                ┌────────────────────┐
                │ Sweep Unmarked     │
                │ Objects            │
                └─────────┬──────────┘
                          │
                          ▼
                ┌────────────────────┐
                │ Free Memory Holes  │
                └────────────────────┘

Advantages

Problems

Fragmentation

After repeated allocations and frees:

[A][_][C][_][E][_][G]

Memory becomes fragmented into holes.

Large allocations may fail even when total free memory exists.

Stop-The-World Pauses

Applications are often paused during collection.

Poor Locality

Live objects become scattered through memory.


Mark-Sweep-Compact

To solve fragmentation, compacting collectors move live objects together.

Flow Diagram

Before Compaction:

[A][_][C][_][E][_][G]

After Compaction:

[A][C][E][G][_][_][_]

Advantages

Problems

Object Movement Complexity

Moving objects requires updating:

Longer Pauses

Compaction is expensive.

Runtime Complexity

The runtime must coordinate relocation safely.


Generational Garbage Collection

Modern runtimes optimize around one observation:

Most objects die young.

The heap is divided into generations.

Flow Diagram

             ┌────────────────────┐
             │  New Allocation    │
             └─────────┬──────────┘
                       │
                       ▼
             ┌────────────────────┐
             │ Young Generation   │
             │   (Nursery)        │
             └─────────┬──────────┘
                       │
                Minor Collection
                       │
        ┌──────────────┴──────────────┐
        │                             │
        ▼                             ▼
┌────────────────────┐   ┌────────────────────┐
│ Dead Objects Freed │   │ Survivors Promoted │
└────────────────────┘   └─────────┬──────────┘
                                    │
                                    ▼
                         ┌────────────────────┐
                         │ Old Generation     │
                         └─────────┬──────────┘
                                   │
                           Major Collection

Advantages

Problems

Massive Complexity

Requires:

Reduced Determinism

Collection timing becomes heuristic-driven.

Shared Heap Coordination

Multiple threads must cooperate with the collector.


Concurrent / Low-Latency Collectors

Modern runtimes such as:

attempt to reduce pauses by performing GC concurrently with application threads.

Flow Diagram

Application Threads
        │
        ├── Continue Running
        │
        ▼
Concurrent GC Threads
        │
        ├── Background Marking
        ├── Incremental Relocation
        ├── Barrier Tracking
        └── Heap Coordination

Advantages

Problems

Extreme Runtime Complexity

Requires:

Higher CPU Overhead

GC becomes part of normal runtime execution.

Harder Debugging

Behavior becomes timing-sensitive.


Why AiVM Is Taking a Different Direction

AiVM is not trying to become:

Instead, AiVM is optimized for:

These goals change the memory strategy entirely.


The AiVM Direction: Deterministic Memory Regions

Rather than relying on runtime heuristics to decide object lifetimes, AiVM uses explicit lifetime regions.

Core Idea

Data survives only when it crosses explicit deterministic boundaries.

Flow Diagram

             ┌────────────────────┐
             │ Parse / Eval Work  │
             └─────────┬──────────┘
                       │
                       ▼
            ┌──────────────────────┐
            │ Scratch / Temp       │
            │ Region               │
            └─────────┬────────────┘
                      │
            Explicit Safe-Point Boundary
                      │
        ┌─────────────┴─────────────┐
        │                           │
        ▼                           ▼
┌────────────────────┐   ┌──────────────────────────┐
│ Temporary Data     │   │ Explicitly Promoted Data │
│ Destroyed/Reset    │   │ Survives Boundary        │
└────────────────────┘   └──────────┬───────────────┘
                                     │
                                     ▼
                         ┌──────────────────────────┐
                         │ Long-Lived Region        │
                         │ Module / Session / Blob  │
                         └──────────┬───────────────┘
                                    │
                         Explicit Release / Dispose
                                    │
                                    ▼
                         ┌──────────────────────────┐
                         │ Region Reset / Cleanup   │
                         └──────────────────────────┘

Deterministic Safe Points

AiVM cleanup and compaction occur only at explicit boundaries:

No hidden background collector.

No heuristic object aging.

No concurrent relocation.


Worker-Local Heaps

AiVM concurrency is based on isolation.

Flow Diagram

Worker A ── Local Heap ─┐
                        │
Worker B ── Local Heap ─┼──► Deterministic Queue
                        │
Worker C ── Local Heap ─┘
                                  │
                                  ▼
                       UI / Semantic Thread
                           Applies Changes

Workers:

All observable state changes occur through deterministic queue dispatch.


Why This Fits AiVectra

AiVectra requires:

Traditional shared mutable heaps complicate:

AiVM’s direction keeps UI semantics simple:

Workers do work.
UI thread applies deterministic results.

Resource-Bounded Execution

AiVM is also introducing deterministic cumulative resource accounting:

This supports:


Why Not Full Concurrent GC?

AiVM may eventually evolve toward more advanced memory management.

But before beta, the project is prioritizing:

The current roadmap intentionally delays:

until after the core runtime architecture stabilizes.


The Key Philosophical Difference

Traditional runtimes optimize for:

huge shared dynamic heaps

AiVM optimizes for:

deterministic lifetime regions
isolated workers
explicit boundaries
message passing
bounded resources

That dramatically reduces how much garbage collection complexity is actually required.


Conclusion

Traditional garbage collectors are extraordinary engineering achievements. They power modern browsers, enterprise servers, mobile runtimes, and massive applications.

But they solve a different problem.

AiVM is intentionally optimizing for:

For those goals, deterministic memory regions and safe-point cleanup are currently a better fit than large concurrent tracing collectors.

The result is a runtime architecture that is:

while still supporting real multithreaded production workloads through isolated workers and deterministic message passing.