keid-lang / keid

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

Implement weak and unowned reference types #75

Open lucasbaizer2 opened 1 year ago

lucasbaizer2 commented 1 year ago

Similar to Swift, weak and unowned references are a must for any language with reference counting and no automatic cycle breaking.

Weak references must be defined as nullable. When an object is deallocated, all weak references to that object get set to null. They do not modify the reference count of the object they refer to.

Unowned references are like weak references, except they are not defined to be nullable. Unowned references assume that the reference is guaranteed to live as long or longer than the object that holds the unowned reference. If an object is deallocated while an unowned reference to it is still held, any usage of that unowned reference will result in an immediate unrecoverable runtime error.