mkirchner/gc logo

mkirchner/gc

Free

Simple, zero-dependency garbage collection for C

FreeFree tier
Type
Open Source

About mkirchner/gc

gc is a simple, conservative, thread-local mark-and-sweep garbage collector for C. It provides drop-in replacements for standard POSIX memory allocation functions (malloc, calloc, realloc, free) and is designed with clarity and learning in mind. Suitable for building interpreters or any C project needing automatic memory management without external dependencies. The implementation includes a core API for starting, stopping, pausing, resuming, and manually triggering garbage collection.

Key Features

Conservative, thread-local mark-and-sweep garbage collection
Drop-in replacement for malloc, calloc, realloc, and free
Zero external dependencies
Simple and clean implementation suitable for learning
Core API for starting, stopping, pausing, resuming, and running GC
Open source (MIT license)

Pros & Cons

Pros
  • Zero external dependencies
  • Simple and clean codebase, easy to understand and modify
  • Compatible with standard POSIX memory functions
  • Suitable for learning and experimentation
  • Supports pause and resume of garbage collection
Cons
  • Conservative collector may not collect all unreachable memory
  • Thread-local only: not suitable for multi-threaded programs
  • Not as optimized as Boehm GC for production use
  • Requires bottom-of-stack address for root finding

Best For

Learning garbage collection concepts and internalsBuilding a LISP interpreter in CEmbedding automatic memory management in C projectsEducational tool for understanding mark-and-sweep algorithms