ID:2956298
 
Applies to:DM Language
Status: Open

Issue hasn't been assigned a status value.
After a discussion on Discord, a new API was proposed for Byondapi to do reference counting.

The problem



Byondapi utilizes reference counting, and currently has two types of references: "temporary" and "permanent" references. This distinction is unlike anything in any other APIs. Temporary references are automatically, cleaned up at the end of the tick, and are returned by most APIs.

Temporary references can be manually destroyed via DecRef, but this exposes the first nasty design flaw: DecRef first destroys permanent references (intended to be used in pair with IncRef), and only then destroys temporary references. This means manually destroying temporary references is never safe if there is a possibility the object might have permanent references to it.

The second problem is with threading: Byondapi is thread safe, making other threads just automatically block on the main thread for any calls that need to. But if a call returns a temporary reference, that temporary reference can be cleaned up by the main thread before the secondary thread has any chance to do anything with it.

Solution



The first problem could be solved by merely adding a second API of the form "DecTempRef", which only ever deletes temporary references. This would be backwards compatible.

The second problem would not be so nice to solve: the only backwards-compatible solution I can come up with is to just provide "v2" versions of all APIs that can possibly return temporary references, and instead make them return solely permanent references. Lummox said he didn't wanna deal with the maintenance hassle of this, so that leaves us with the other option:

Take a breaking change to remove temporary references entirely. This would make it more inline with most other reference counted APIs. Users of Byondapi would need to manually DecRef every reference they get, but realistically most people using Byondapi are using C++ or Rust or something which would handle this automatically. And again, this is basically industry standard, people have been writing COM and CPython code like this for decades.
This got pushed down the page by all the feature request closures prepping for 516's release, but it's an open tab for me, and I also made note of it in the breaking changes sticky in the Beta Bugs forum. This will be addressed in January.