[fpc-devel] Suggestion: reference counted objects

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



Marco van de Voort schrieb:
> In our previous episode, Hans-Peter Diettrich said:
>> 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.
> 
> IMHO weak references trade one manual memory system in for a different
> manual memory system.

Weak references steer/guide *automatic* memory management.

> The hard part of manual memory systems, figuring out how a complex dynamic
> structure deallocates (that is usually tackled by having a bit of design and
> thought go into it), remains.

And this is what the user of such a structure (standard libraries...) 
does not always know. He may be unable to determine the reason for some 
runtime error in his code, when an object was destroyed automagically 
where it should still be alive. The user can debug (and fix) ordinary 
(owner/owned) patterns, implemented in high level code, but not 
table-driven (RTTI) or otherwise hidden (intrinsic) management 
procedures. While the user can change the owner of an object at runtime, 
he cannot change a weak reference into a strong one, without 
recompilation of at least the unit containing that declaration, and 
without figuring out the consequences of such an change.

DoDi




More information about the fpc-devel mailing list