keid-lang / keid

Central repository for the Keid programming language
0 stars 1 forks source link

Add reference cycle detector #39

Open lucasbaizer2 opened 1 year ago

lucasbaizer2 commented 1 year ago

There needs to be a means to detect cyclical references. Programmers should not need to understand and work around the memory model of the language they're programming in when the language intends to be memory safe.

Python, especially CPython, is a good example of this. The author of source code does not need to define weak references, although CPython is a reference-counted (i.e. not mark-and-sweep garbage collected) interpreter. CPython implements this with a cycle detector that is able to determine which pointers are cyclical and then collect their memory.

This could be implemented with keid.unscope, but the overhead of this is significant. It might be a good idea to implement this in the style of a garbage collector; that is, pause execution and determine if any cycles exist. The issue with this alternate implementation is that it requires keeping track of all object pointers, at which point it's a garbage collector with extra steps.

This is a significant issue and should require lots of thought before making a decision and implementation of said decision.