2 ms·
> Of course this approach has its own downside: a program may panic at when dropping an owned value, if it still has one or more references pointing to it. I w
by js8 5y ago
> Of course this approach has its own downside: a program may panic at when dropping an owned value, if it still has one or more references pointing to it.
I wonder if this could be also handled by having a custom error handler available on each created reference, to decide what to do with the "hanging" value, whether to reassign ownership, or invalidate the reference, or panic, or do whatever else.
- rwmj 5y agoYour solution to the supposed overhead of garbage collection is to make every single object fat and have an extra test every time a pointer to an object is dropped?
- js8 5y agoNo, the handler(s) would only be called when the owner wants to dispose the object and there are still references to it.
- rwmj 5y agoHow do you know there are still references without counting them somewhere or inspecting all other objects? And what would the handler really do? What common code has other owners willing to take over ownership (and you have to handle this problem recursively too).
- js8 5y agoIn the article, they already assume reference counting of references, see the previous paragraph: "When the reference goes out of scope, the count is reduced. When an owned value goes out of scope and its reference count is not zero, the program terminates with an error (which I'll refer to as a "panic")."