radical ideas about GC and ARC : need to be time driven?

Manu via Digitalmars-d digitalmars-d at puremagic.com
Tue May 13 05:17:56 PDT 2014


On 13 May 2014 21:42, Kagamin via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> On Tuesday, 13 May 2014 at 07:42:26 UTC, Manu via Digitalmars-d wrote:
>>
>> The other topic is still relevant to me too however (and many others).
>> We still need to solve the problem with destructors.
>> I agree with Andrei, they should be removed from the language as they
>> are. You can't offer destructors if they don't get called.
>
>
> Andrei only said, they are not called sometimes, not always, so we can
> guarantee destructor calls, when it can be guaranteed.

... what?

>> And the usefulness of destructors is seriously compromised if you can't
>> rely
>> on them being executed eagerly. Without eager executed destructors, in
>> many situations, you end up with effective manual releasing the object
>> anyway (*cough* C#), and that implies manually maintaining knowledge
>> of lifetime/end of life and calling some release.
>
>
> I use finalizers in C#, they're useful. I understand, it's a popular
> misunderstanding, that people think, that GC must work like RAII. But GC
> manages only its resources, not your resources. It can manage memory without
> RAII, and it does so. Speaking about eager resource management, we have
> Unique and RefCounted in phobos, in fact, files are already managed that
> way. What's problem?

It completely undermines the point. If you're prepared to call
finalise, when you might as well call free... Every single detail
required to perform full manual memory management is required to use
finalise correctly.
I see absolutely no point in a GC when used with objects that require
you to manually call finalise anyway.

>> Do we ARC just those objects that have destructors like Andrei
>> suggested? It's a possibility, I can't think of any other solution. In
>> lieu of any other solution, it sounds like we could very well end up
>> with ARC tech available one way or another, even if it's not
>> pervasive, just applied implicitly to things with destructors.
>
>
> BTW, I don't see how ARC would be more able to call destructors, than GC. If
> ARC can call destructor, so can GC. Where's the difference?

ARC release is eager. It's extremely common that destructors either
expect to be called eagerly, or rely on proper destruction ordering.
Otherwise you end up with finalise again, read: unsafe manual memory
management :/


More information about the Digitalmars-d mailing list