Tech News
← Back to articles

C3 solved memory lifetimes with scopes

read original related products more articles

2025-07-11

Modern languages offer a variety of techniques to help with dynamic memory management, each one a different tradeoff in terms of performance, control and complexity. In this post we’ll look at an old idea, memory allocation regions or arenas, implemented via the C3 Temp allocator, which is the new default for C3.

The Temp allocator combines the ease of use of garbage collection with C3’s unique features to give a simple and (semi)-automated solution within a manual memory management language. The Temp allocator helps you avoid memory leaks, improve performance, and simplify code compared to traditional approaches.

Memory allocations come in two broad types stack allocations which are compact, efficient and automatic and heap allocations which are much larger and have customisable organisation. Custom organisation allows both innovation and footguns in equal measure, let’s explore those.

Memory Leaks

When we dynamically allocate memory, with say malloc() typically we need to free() it afterwards, otherwise we can’t use that memory until the OS process exits. If that memory isn’t being used and it has not been freed this is called a memory leak and can lead to restricting or running out of available system memory.

Avoiding Memory Leaks

Common solutions are RAII, reference counting or garbage collection which automatically free those variables.

Each method has different tradeoffs.

RAII needs classes or structs to manage their own memory cleanup with a lot of extra code.

... continue reading