This project implements a minimal virtual machine and a full mark-and-sweep garbage collector in C.
It demonstrates low-level memory management, object graph traversal, and runtime system design.
-
Custom object system
-
Frame-based root tracking
-
Mark phase
-
Trace phase
-
Sweep phase
-
Supports:
- Integers
- Strings
- Arrays
- Vector3 objects
-
Proper handling of cyclic references
-
Memory verified using Valgrind
This project showcases understanding of:
- Heap memory management
- Object lifetime tracking
- Root set identification
- Graph traversal (mark phase)
- Recursive tracing of reachable objects
- Safe sweeping of unreachable objects
- Designing a small runtime system in C
src/ → Core runtime implementation
include/ → Header files
tests/ → Munit test suite
external/ → Third-party test library
Makefile → Build configuration
From the project root:
make
./gc_tests
valgrind --leak-check=full ./gc_tests
You should see:
All heap blocks were freed -- no leaks are possible
The garbage collector works in three phases:
-
Mark
Objects referenced from active VM frames are marked as reachable. -
Trace
Reachable objects recursively mark any objects they reference (arrays, vectors, etc.). -
Sweep
Unmarked objects are freed from the heap.
This ensures:
- No memory leaks
- Safe cleanup of cyclic references
- Proper object lifetime management
This project demonstrates practical knowledge of:
- Systems programming in C
- Manual memory management
- Runtime architecture
- Garbage collector design
- Debugging memory issues using Valgrind
It reflects understanding of how high-level languages manage memory internally.
- Generational garbage collection
- Hybrid reference counting model
- Bytecode interpreter
- Full scripting language built on top of this VM
- Performance benchmarking
Arav Pradosh