Master the fundamental concepts of garbage collection through this focused micro-challenge.
You have read the whole brief, and the concepts above stay free on every task. Writing and running the code needs a plan.
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
Every task includes starter code, theory, and hidden tests so you can implement and verify locally in the browser.
How it worksConservative GC treats stack and register words as possible pointers. If a word points into the heap, keep the object. Boehm-Demers-Weiser GC powers some C/C++ runtimes where precise roots are unavailable.
Walk stack slots; if value looks like heap address and aligns to object boundary, treat as reference. No relocation possible because any word might be a disguised pointer.
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 conservative garbage collection root scanning. This exercise requires walking stack words, testing heap likelihood, and marking objects without exact pointer maps.
Implement a conservative collector in the style of the Boehm GC, used by C programs and language runtimes that can't tell pointers from integers: treat every word on the stack and in reachable objects as a potential pointer, keep alive any object it points into, and measure the cost: objects kept alive by integers that merely look like addresses.
cLoading…
VALUE is hex (0x...) or decimal. The optional int tag says what the program meant: the value is really an integer. The collector cannot see this tag; it is only used for the report.
interior yes: lies anywhere in [start, start + SIZE).For every stack or heap word that hits an object:
cLoading…
Then:
cLoading…
Values print in lower-case hex.
Input:
cLoading…
Output:
cLoading…
int-tagged words) for the false-retention report.Hidden tests cover interior no, integers that land on object start addresses, pointers hidden inside heap objects, and values that point just past the end of an object.