Escaping the Tyranny of the GC: std.rcstring, first blood

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Sun Sep 14 20:53:13 PDT 2014


On 9/14/14, 7:52 PM, Vladimir Panteleev wrote:
> On Monday, 15 September 2014 at 02:26:19 UTC, Andrei Alexandrescu wrote:
>> The road there is long, but it starts with the proverbial first step.
>
> An unrelated question, but how will reference counting work with classes?
>
> I've recently switched my networking library's raw memory wrapper to
> reference counting (previously it just relied on the GC for cleanup),
> and it was going well until I've hit a brick wall.
>
> The thing with reference counting is it doesn't seem to make sense to do
> it half-way. Everything across the ownership chain must be reference
> counted, because otherwise the non-ref-counted link will hold on to its
> ref-counted child objects forever (until the next GC cycle).
>
> In my case, the classes in my applications were holding on to my
> reference-counted structs, and wouldn't let go until they were
> eventually garbage-collected. I can't convert the classes to structs
> because I need their inheritance/polymorphism, and I don't see an
> obvious way to refcount classes (RefCounted explicitly does not support
> classes).
>
> Am I overlooking something?

At least for the time being, bona fide class objects with refcounted 
members will hold on to them until they're manually freed or a GC cycle 
comes about.

We're thinking of a number of schemes for reference counted objects, and 
we think a bottom-up approach to design would work well here: try a 
simple design and assess its limitations. In this case, it would be 
great if you tried to use RefCounted with your class objects and figure 
out what its limitations are.


Thanks,

Andrei



More information about the Digitalmars-d mailing list