JoeStrout / miniscript

source code of both C# and C++ implementations of the MiniScript scripting language
MIT License
285 stars 64 forks source link

C++: change garbage collection to work with orphaned cycles #127

Open JoeStrout opened 9 months ago

JoeStrout commented 9 months ago

The C++ implementation currently uses reference-counting, which is relatively fast and simple, but can leak circular references.

Switch to another form of garbage collection to fix this problem and bring behavior in line with the C# implementation. Probably either mark-and-sweep, or Cheney's algorithm. The latter sounds like it might perform better, and is simple to implement; see: https://arxiv.org/pdf/1505.00017.pdf

JoeStrout commented 9 months ago

Note that strings are probably a special case, because (1) the are used a lot, and (2) they cannot contain any other references.

So it might make sense to continue using reference-counting for them, reducing the amount of work the GC has to do.