More radical ideas about gc and reference counting

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Wed Apr 30 19:20:30 PDT 2014


On Wed, 30 Apr 2014 21:51:38 -0400, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:

> On 4/30/14, 6:04 PM, Steven Schveighoffer wrote:
>> destructors are for cleaning up non-GC resources. File handles, malloc'd
>> memory, etc. I don't see why these need to be eliminated.
>
> Virtually all GCs are known to be horrible at managing scarce resources  
> (including memory itself).

The destructor can be a crutch, but it's not good to leave open resources  
when the user of your code has not cleaned them up manually.

I can see no reason to disallow destruction from cleaning up resources  
that nobody else has managed to clean up.

The largest problem with D destructors comes from trying to clean up D  
objects in destructors of structs, that you never expected to be done via  
the GC.

Cleaning up files and malloc'd memory is not an issue.

-Steve


More information about the Digitalmars-d mailing list