|
|
|
|
|
by _flux
1831 days ago
|
|
Tracing GC is troublesome for any non-memory resource, such as network connection or file handle, due to its untimely release, but otherwise I actually agree: reference counting is a GC mechanism—not a very good one, but it's the only one I'm aware of that works both for memory and resources. I would enjoy someone test a model where the type system guarantees (or at least lets you detect the situation) that you cannot store such non-memory objects behind a traced GC node (these would include plain memory objects that need to be registered/unregistered precisely). It might be that it would be needlessly annoying to use just compared to just RC. Or maybe it would be best of both worlds? |
|
You can even turn it into RAII proper, by turning into a compilation error not handling those interfaces properly.
Again with .NET, there are SafeHandles as well, alongside the MarshalInterop APIs.
This is nothing new actually, Mesa/Cedar for Xerox PARC used reference counting with a cycle collector, while other descendent languages down to Modula-3 and Active Oberon always combined value types, tracing GC and C++ like resource handling capabilities.
Oh Common Lisp also has similar capabilities, specially the ZetaLisp predecessor from Lisp Machines.
Then Eiffel not only had this, it was also probably the first Algol like language to support non nullable references.
Sadly they decided to ignore all of this in Java, and then its world domination kind of made everyone else ignore it as well.
Thankfully even Java is improving their story in this regard, while languages like D, Nim and yes .NET kind of show what was already available for several decades.