Mark-and-Sweep Garbage Collector

  scripts
  sprites
See inside
Instructions

This isn't really a very exciting demo, sorry!

Notes and Credits

Even though your computer has a finite amount of memory, many programming languages give the programmer the illusion of having infinite memory. This works by essentially going through and freeing up space wherever possible by discarding "trash" memory that isn't useful anymore. We call this "garbage collection". This project is an implementation of a garbage collector called a "mark-and-sweep" collector. By analogy, it works by first tagging everything as either "trash" or "not-trash", then throwing out the trash and moving all the "not-trash" over to one side to make space in your house.

The reason this is hard is because it's hard to tell what "trash" is. You know how sometimes your parents save the boxes and receipts of appliances they buy for warranty/return policies? That box isn't really being used, but it's not trash because it *could* be used.

Years later, your parents may throw out or sell the appliance, but forget to throw out the box! Then the box suddenly becomes trash. A garbage collector needs to keep track of all these relationships between objects so that it doesn't throw out something that could be useful later on.

Shared: 30 Apr 2016 Modified: 30 Apr 2016
Favorite this project 1
Love this project 3
Total views 68
View the remix tree  1
  
More projects by Hardmath123