Master the fundamental concepts of garbage collection through this focused micro-challenge.
Strong refs keep objects alive; weak refs observe without retaining. Java WeakReference and Swift weak let caches and parent pointers avoid cycles. When only weak refs remain, object is collectable.
Weak ref field does not increment refcount or mark bit. On collection, weak refs null out. Finalizers run once after weak resolution in some runtimes.
cLoading…
Production compilers embed this step inside a longer pipeline. GCC flows through cpp, cc1, assembly, and ld; Clang uses the driver, Sema, LLVM IR passes, and a target backend. LLVM bitcode, JVM bytecode, and WASM are other familiar IRs at the same layer. The exercise isolates one pass so you can test it alone before chaining it to the next stage.
You will implement weak references for breaking reference cycles. This exercise asks you to track weak slots separately from strong roots so objects are collected when only weakly reachable.
Implement weak references in C with a simulated garbage collector.
Requirements:
Test:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github