[fpc-devel] Suggestion: reference counted objects

Hans-Peter Diettrich DrDiettrich1 at aol.com
Sun Sep 21 05:14:00 CEST 2014


Boian Mitov schrieb:
> The short story is that any approach has issues.
> The component container approach has issue of a single ownership with 
> the easy loss of pointers.
> The ref counting has the danger of circular references.
> The GC has the non deterministic behavior (Actually I proposed a 
> deterministic/semideterministic GC algorithm ~8 years ago or so, but 
> that is a different story).

I don't like the use of "GC" as a synonym for *mark-sweep* garbage 
collection only. Wikipedia also states Reference Counting as just 
another form of garbage collection.

> The point is that even with GC the developer is still required to 
> carefully manage resources, and GC tends to make it even more complex.
>> From all the the above approaches the ARC with optional Weak pointers 
>> is the 
> easiest to manage and the one that tends to lead to the least problems 
> IMHO .

ACK - except for Weak references. Weak references turn the conservative 
memory management into an aggresive/optimistic one, with unpredictable 
consequences.

IMO Weak references should be reserved for users who accept possible 
consequential problems, but should never be used in standard libraries. 
At least I'd suggest to make weak references subject to an compiler 
switch, so that every user has a chance to disable them in case of trouble.

DoDi




More information about the fpc-devel mailing list