Over on /tg/, we have a /datum/weakref class: https://github.com/tgstation/tgstation/blob/master/code/ datums/weakrefs.dm
This allows for weak references, AKA references to other datums without counting as strong references. In the code, this means that when an object is destroyed, the next time the weakref is resolve()'d, it returns null.
This is good for non-owning relationships (such as the ability to create weak `owner` variables inside children) without much overhead, while also creating an explicit contract as to what the variable is for.
However, our implementation has some limitations.
Firstly, it does not have any ability to support types. We must manually re-cast the type every time it is used.
Second, it most likely takes up significantly more memory than a normal ref.
I would like to see official weakrefs be added to BYOND, as it would solve both these issues while ideally letting us preserve the good.
ID:2662462
Mar 9 2021, 12:13 am
|
|||||||
| |||||||
Mar 9 2021, 12:31 pm
|
|
This would be a very useful vanilla addition for better GC
|
Nevermind, they are only references to the specific name and not to the object:
/datum/weakref create_ref() then resolve_ref() gives null because its a reference to "myself" and not "src" |