Destructor nonsense on dlang.org

Alex Rønne Petersen alex at lycus.org
Thu May 24 07:56:31 PDT 2012


On 24-05-2012 16:53, Steven Schveighoffer wrote:
> On Thu, 24 May 2012 10:30:02 -0400, Alex Rønne Petersen <alex at lycus.org>
> wrote:
>
>> On 24-05-2012 15:49, Steven Schveighoffer wrote:
>>> On Thu, 24 May 2012 09:47:23 -0400, deadalnix <deadalnix at gmail.com>
>>> wrote:
>>>
>>>> Le 24/05/2012 14:54, Peter Alexander a écrit :
>>>>> On Thursday, 24 May 2012 at 12:21:02 UTC, Alex Rønne Petersen wrote:
>>>>>> Hi,
>>>>>>
>>>>>> http://dlang.org/class.html#Destructor
>>>>>>
>>>>>> "The garbage collector is not guaranteed to run the destructor for
>>>>>> all
>>>>>> unreferenced objects."
>>>>>>
>>>>>> What the *hell*? So resources are allowed to arbitrarily leak and the
>>>>>> programmer has to actually expect this to happen?
>>>>>>
>>>>>> I really, really hope that this is a documentation error or early
>>>>>> design decision that has since been rectified but with lack of
>>>>>> documentation updates.
>>>>>
>>>>> I'm pretty sure it's the same in Java.
>>>>>
>>>>> Finalizers (a.k.a. class destructors) are practically useless.
>>>>
>>>> Java finalizer is a pretty bad design decision. Let's not reproduce
>>>> error made in Java in D's destructors.
>>>
>>> You actually need a finalizer if you want to have resources that aren't
>>> GC allocated.
>>>
>>> -Steve
>>
>> But that doesn't mean we should have Java finalization. There are many
>> different forms of finalization, and I do agree that Java is the worst
>> of all of them.
>
> I only found one definition for finalizer on wikipedia, and it fits D's
> definition.
>
> What I think we need is a dispose pattern for objects, like Tango has.
>
> -Steve

Just look at /usr/include/gc/gc.h (from libgc, the Boehm-Demers-Weiser 
GC). It has 3 (if not 4) different kinds of finalization. To be 
specific, the finalization I believe we need is the *_no_order behavior. 
This is the behavior C# and the CLR follow.

-- 
Alex Rønne Petersen
alex at lycus.org
http://lycus.org


More information about the Digitalmars-d mailing list