corto
corto copied to clipboard
Improve memory management
Objects are being memory managed using reference counting. When an object reaches reference count zero it will be destructed. The current approach has however some issues.
First and foremost cycles are not being collected. Since proper detection and collection of cycles requires a "stop the world" approach in some way or another where all operations are halted while the garbage collector is doing its work, this will be tricky to implement.
If a cycle detector is implemented, a very carefully designed algorithm must be put in place that properly destructs objects in a cycle. The issue here is that when A is pointing to B, and B to A, then A is destructed, then B is destructed, and B accesses A in its destructor, there is a potential for error.
To solve this, object destructors must be resilient against encountering objects for which the destructor has been called. Cleaning up resources can only occur after for all objects in a cycle the destructor has been called.
For those applications where garbage collection is undesirable, weak references shall be supported. A weak reference shall update its value to null upon destruction of the object it is pointing to.