Would you pay for GC?

Steven Schveighoffer schveiguy at gmail.com
Tue Jan 25 14:44:55 UTC 2022


On 1/25/22 4:32 AM, Paulo Pinto wrote:
> On Tuesday, 25 January 2022 at 08:24:22 UTC, rikki cattermole wrote:
>>
>> On 25/01/2022 8:22 PM, Elronnd wrote:
>>> On Tuesday, 25 January 2022 at 07:13:41 UTC, Paulo Pinto wrote:
>>>> ARC will also not compete, unless one goes the extra mile of making 
>>>> the compiler ARC aware, elide retain/release calls, do cascade 
>>>> deletions in background threads, take care on cascade deletions to 
>>>> avoid stack overflows on destructor calls, provide multicore 
>>>> friendly versions of them,.....
>>>
>>> Indeed.  See Bacon et al, 'Unified Theory of Garbage Collection': 
>>> increasingly sophisticated RC approaches tracing (and vice versa).  
>>> So it's a bit strange to assume we can do one but not the other.  And 
>>> tracing makes a better starting point due to the generational 
>>> hypothesis.
>>
>> RC shines for when deterministic destruction is required.
>>
>> ...
> 
> That is the naive idea, until a cascade deletion of a graph based 
> datastructure happens.

I use ARC for determinism only, not memory deallocation: 
https://github.com/schveiguy/iopipe/blob/master/source/iopipe/refc.d

e.g., when I want the last reference to a buffered output stream to 
flush its buffer and close the file when going out of scope. I don't 
care about the memory management, that's fine for the GC to clean up.

As an added benefit, it's trivially `@safe`.

-Steve


More information about the Digitalmars-d mailing list