draft proposal for ref counting in D

Walter Bright newshound2 at digitalmars.com
Wed Oct 9 18:46:16 PDT 2013


Rainer Schuetze wrote:

On 26.06.2013 13:12, Michel Fortin wrote:
 > Le 26-juin-2013 à 5:38, Walter Bright  a
 > écrit :
 >
 >> On 6/26/2013 12:19 AM, Rainer Schuetze wrote:
 >>>
 >>> As Michel also said, the reference count does not have to be in
 >>> inside the object itself, so we might want to allow reference
 >>> counting on other types aswell.
 >>
 >> That opens the question of what is the point of other RC types? For
 >> example, C++ can throw any type - but it turns out that throwing
 >> anything but class types is largely pointless.
 >
 > RC is just another garbage collection scheme. You might favor it for
 > its performance characteristics, its determinism, or the lower memory
 > footprint.
 >
 > Or you might need it to interact with foreign code that relies on it
 > (COM, Objective-C, etc.), in which case it needs to be customizable
 > (use the foreign implementation) or be manually managed.
 >
 > That's two different use cases. And in the later case you can't use
 > the GC to release cycles because foreign code is using memory
 > invisible to the GC. It is important to note that when foreign code
 > calls AddRef you don't want the GC to collect that object, at least
 > not until Release is called.

That means you have to maintain two reference counts if you have both ARC and 
COM used in the same class. ARC can only release the object if both counters are 
0, while the COM implementation has to add/remove roots to the GC when counting 
from/to 0 to avoid that the object is collected while external references exist.



More information about the Digitalmars-d mailing list