This assignment is not for credit, but if you’re interested enough in garbage collection to try it, the instructor will be happy to provide feedback.
Add garbage collection to your msdscript
implementation as shown in the videos and slides.
Some notes and tips:
#define USE_GARBAGE_COLLECTOR 1
so you can switch between plain pointers (leaks), shared_ptr
(crashes when trying to free a long data chain), or garbage collection.--interp
will leak with garbage collection, and that's ok. Let’s just say that --step
is the right way to run.GCable::reset
function as below to use for testing, because your non-stepping tests will send the collector into out_of_memory = true
mode. You’ll need to reset the allocator just before stepping tests that cooperating with the collector.
void GCable::reset() {
heap_size = (8*1024);
to_space = nullptr;
from_space = nullptr;
allocation_offset = 0;
out_of_memory = false;
Env::empty = NEW(EmptyEnv)();
Cont::done = NEW(DoneCont)();
}