We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Sweep

Sweep is easy! Trace was probably the hardest part of the garbage collector.

Every object now has an is_marked field that we can use to determine if an object is reachable or not. All we need to do is iterate over all the objects in the VM and free any object that is not marked. Once it's freed, we can also remove it from our VM.

One more thing that's not obvious about sweep(): Any object that is marked (we don't want to free it right now) needs to be reset to is_marked = false. That way the next time the mark phase runs, if it's not marked again it will be freed in the next cycle.

Assignment

Hope you liked the course! Great work.

Hint

You can use the snek_object_free function to free the objects