4 ms·
> just give every allocated object a couple of reference counts. Works great with a single thread.
by akira2501 2y ago
> just give every allocated object a couple of reference counts.
Works great with a single thread.
- o11c 2y agoMulti-threaded refcounts aren't actually that hard? There's overhead (depending on how much you're willing to annotate it and how much you can infer), but the only "hard" thing is the race between accessing a field and and changing the refcount of the object it points to, and [even ignoring alternative CAS approaches] that's easy enough if you control the allocator (do not return memory to the OS until all running threads have checked in). Note that, in contrast the the common refcount approach, it's probably better to introduce a "this is in use; crash on free" flag to significantly reduce the overhead.