While working on adding the new type system to Parable I decided to rewrite the garbage collector. This has finally fixed some longstanding issues and will be very beneficial going forward.
The previous garbage collector was very simple: it scanned all named slices, appending all values they contained as probable references. Anything not in this set was then released. There were a few issues:
- Without type information a lot of unneeded slices were being kept
- The code to find references didn't always follow all dependent chains, so some neccessary slices were being discarded
- Pointers on the stack were not scanned
These issues led to a number of bugs, and prevented me from making good use of the garbage collector. With the addition of type information it became possible to resolve these issues, and make it into a fully functional part of the language.
So the new approach is:
- Scan all named slices for strings, comments, pointers, and function calls
- Scan all references to pointers and function calls for the above types. Repeat until all nested references have been scanned
- Repeat the above process for all values on the stack
- Remove any duplicates
- Release any allocated slices that are not in the above set
At this point everything is working. I haven't completely tested it, but it's certainly more stable than the previous implementation. Further work on this will be done as necessary, but for now I'm moving onto other tasks.