Jump to page: 1 27  
Page
Thread overview
Destructor nonsense on dlang.org
May 24, 2012
Thor
May 24, 2012
Thor
May 24, 2012
ponce
May 24, 2012
Tove
May 24, 2012
David Nadlinger
May 24, 2012
David Nadlinger
May 24, 2012
Tove
May 24, 2012
foobar
May 24, 2012
Tove
May 24, 2012
Tove
May 25, 2012
Jacob Carlborg
May 25, 2012
foobar
May 25, 2012
Jacob Carlborg
May 25, 2012
foobar
May 26, 2012
Jacob Carlborg
May 26, 2012
foobar
May 26, 2012
Jacob Carlborg
May 26, 2012
Artur Skawina
May 25, 2012
Regan Heath
May 24, 2012
David Nadlinger
May 25, 2012
Mehrdad
May 25, 2012
Mehrdad
May 25, 2012
Jonathan M Davis
May 25, 2012
Mehrdad
May 25, 2012
Mehrdad
May 26, 2012
deadalnix
Nov 12, 2013
Michael
May 24, 2012
deadalnix
May 24, 2012
Michel Fortin
May 24, 2012
Michel Fortin
May 24, 2012
Tove
May 24, 2012
Peter Alexander
May 24, 2012
Michel Fortin
May 24, 2012
Russel Winder
May 24, 2012
deadalnix
May 24, 2012
Jacob Carlborg
May 24, 2012
David Nadlinger
May 24, 2012
deadalnix
May 25, 2012
Mehrdad
May 24, 2012
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.

-- 
Alex Rønne Petersen
alex@lycus.org
http://lycus.org
May 24, 2012
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.

use "clear", or "scope (exit)" or "structs" or scoped!... etc.

There could always be a false reference... so you cannot depend on automatically releasing resources in a class destructor.

May 24, 2012
On 24-05-2012 14:33, Thor wrote:
> 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.
>
> use "clear", or "scope (exit)" or "structs" or scoped!... etc.

I know.

>
> There could always be a false reference... so you cannot depend on
> automatically releasing resources in a class destructor.
>

False pointers have nothing to do with it. The GC should free and finalize all objects on shutdown, meaning the finalizer runs *sooner or later*. If this is the case (which I do believe it is), then the docs are very wrong.

-- 
Alex Rønne Petersen
alex@lycus.org
http://lycus.org
May 24, 2012
On 2012-05-24 12:21:01 +0000, Alex Rønne Petersen <alex@lycus.org> said:

> 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 think it means that objects not collected when the program terminates will never be, and thus the destructor will not be called.

There's also the issue of false pointers that can prevent some objects from being collected.

More generally, you can't really count on the destructor being called because the GC is free to decide when to recycle memory. An implementation that never collects and always allocate new memory is a perfectly valid GC implementation, even though it might not be very practical in most cases.

-- 
Michel Fortin
michel.fortin@michelf.com
http://michelf.com/

May 24, 2012
On Thursday, 24 May 2012 at 12:38:45 UTC, Alex Rønne Petersen wrote:
> On 24-05-2012 14:33, Thor wrote:
>> 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.
>>
>> use "clear", or "scope (exit)" or "structs" or scoped!... etc.
>
> I know.
>
>>
>> There could always be a false reference... so you cannot depend on
>> automatically releasing resources in a class destructor.
>>
>
> False pointers have nothing to do with it. The GC should free and finalize all objects on shutdown, meaning the finalizer runs *sooner or later*. If this is the case (which I do believe it is), then the docs are very wrong.

__gshared uint my_false_ptr;

even if we are shutting down, the static references doesn't disappear... or did I miss something?

May 24, 2012
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.
May 24, 2012
On Thu, 24 May 2012 08:54:45 -0400, Peter Alexander <peter.alexander.au@gmail.com> wrote:

> 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.

From Java spec:

"The Java programming language does not specify how soon a finalizer will be invoked, except to say that it will happen before the storage for the object is reused"

So yeah, there is no guarantee when a finalizer will be invoked.

However, I'd tend to believe Java implementations will attempt to invoke all finalizers of objects left on the heap at program shutdown.

I think D is the same too, as long as termination is normal (i.e. not from throwing an Error).

-Steve
May 24, 2012
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.
May 24, 2012
On Thu, 24 May 2012 09:47:23 -0400, deadalnix <deadalnix@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
May 24, 2012
On 2012-05-24 13:38:01 +0000, "Steven Schveighoffer" <schveiguy@yahoo.com> said:

> However, I'd tend to believe Java implementations will attempt to invoke
> all finalizers of objects left on the heap at program shutdown.

In Java you can call System.runFinalizersOnExit(true), but the default is false and this method has been deprecated because unsafe in multithreaded environments.

<http://docs.oracle.com/javase/6/docs/api/java/lang/System.html#runFinalization()>


-- 


Michel Fortin
michel.fortin@michelf.com
http://michelf.com/

« First   ‹ Prev
1 2 3 4 5 6 7