More radical ideas about gc and reference counting

w0rp via Digitalmars-d digitalmars-d at puremagic.com
Sat May 3 02:36:43 PDT 2014


On Friday, 2 May 2014 at 00:45:42 UTC, Andrei Alexandrescu wrote:
> Here's where the point derails. A struct may be preexisting; 
> the decision to define a destructor for it and the decision to 
> use polymorphism for an object that needs that structure are 
> most of the time distinct.
>
> Andrei

I wonder how common the pattern of putting a struct with a 
destructor in a class actually is. It might be a case for 
defining data structures with GC allocation rather than reference 
counting (as in std.container). I suppose a choice of allocator 
will change this quite a lot. That which is allocated with 
reference counting could uniquely hold its container member and 
then call the destructor when it dies, or similar.

I find it kind of a funny thing to put something like a File 
inside of a class. I have always seen the mix of GC and resource 
management as more managing resources like Files in scopes and 
reading data from the resources which turn into objects in memory 
which are garbage collected. Not allocating garbage collected 
objects which contain resources.


More information about the Digitalmars-d mailing list