The "no gc" crowd

Michel Fortin michel.fortin at michelf.ca
Thu Oct 10 04:17:13 PDT 2013


On 2013-10-10 01:21:25 +0000, "deadalnix" <deadalnix at gmail.com> said:

> On Wednesday, 9 October 2013 at 23:37:53 UTC, Michel Fortin wrote:
>> In an ideal world, we'd be able to choose between using a GC or using 
>> ARC when building our program. A compiler flag could do the trick. But 
>> that becomes messy when libraries (static and dynamic) get involved as 
>> they all have to agree on the same codegen to work together. Adding 
>> something to mangling that would cause link errors in case of mismatch 
>> might be good enough to prevent accidents though.
> 
> ObjC guys used to think that. It turns out it is a really bad idea.

Things were much worse with Objective-C because at the time there was 
no ARC, reference-counting was manual and supporting both required a 
lot of manual work. Supporting the GC wasn't always a easy either, as 
the GC only tracked pointers inside of Objective-C objects and on the 
stack, not in structs on the heap. The GC had an implementation problem 
for pointers inside static segments, and keeping code working on both a 
GC and reference-counted had many perils.

I think it can be done better in D. We'd basically just be changing the 
GC algorithm so it uses reference counting. The differences are:

1. unpredictable lifetimes -> predictable lifetime
2. no bother about cyclic references -> need to break them with "weak"

The later is probably the most problematic, but if someone has leaks 
because he uses a library missing "weak" annotations he can still run 
the GC to collect them while most memory is reclaimed through ARC, or 
he can fix the problematic library by adding "weak" at the right places.


-- 
Michel Fortin
michel.fortin at michelf.ca
http://michelf.ca



More information about the Digitalmars-d mailing list