Jump to page: 1 2 3
Thread overview
[Issue 2834] Struct Destructors are not called by the GC, but called on explicit delete.
Jul 03, 2014
Benoit Rostykus
Jul 04, 2014
Jonathan M Davis
Jul 04, 2014
Jonathan M Davis
Jul 04, 2014
Orvid King
Jul 04, 2014
David Nadlinger
Jul 04, 2014
Orvid King
Jul 04, 2014
Jonathan M Davis
Jul 05, 2014
Orvid King
Jul 05, 2014
Dmitry Olshansky
Jul 05, 2014
Rainer Schuetze
Jul 18, 2014
Orvid King
Aug 29, 2014
Orvid King
Aug 29, 2014
Orvid King
Aug 30, 2014
Orvid King
July 03, 2014
https://issues.dlang.org/show_bug.cgi?id=2834

Benoit Rostykus <benoit.rostykus@adroll.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |benoit.rostykus@adroll.com

--- Comment #12 from Benoit Rostykus <benoit.rostykus@adroll.com> ---
AdRoll (the company I work for) just put a $1000 bounty on this bug: https://www.bountysource.com/issues/2900969-struct-destructors-are-not-called-by-the-gc-but-called-on-explicit-delete

We are really excited about D, and would generally love to see any work on improving D's GC!

--
July 04, 2014
https://issues.dlang.org/show_bug.cgi?id=2834

Jonathan M Davis <jmdavisProg@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg@gmx.com

--- Comment #13 from Jonathan M Davis <jmdavisProg@gmx.com> ---
I'd strongly argue that we make it so that struct destructors get called when the memory for a struct is freed on the GC heap (though that pretty requires what precise heap scanning requires as Sean points out). However, it should be pointed out that there's no guarantee (and likely never will be a guarantee) that everything on the heap will be collected, which would mean that it will never be guaranteed that all struct destructors will be called when on the heap - just that they would be called in the cases where the struct is collected and freed by the GC.

So, while we should be able to make it so that struct destructors on the GC heap get called much more (as opposed to never), it will almost certainly be the case that the non-GC heap (along with some kind of manual memory management or reference-counting) will have to be used if it's _required_ that the destructor be run (though technically, not even that would guarantee it, since the program could still segfault, or an Error could be thrown, or the computer could lose power or some other incident could occur which would make it so that the program terminated prematurely, in which case, the destructors wouldn't be run).

--
July 04, 2014
https://issues.dlang.org/show_bug.cgi?id=2834

--- Comment #14 from Jonathan M Davis <jmdavisProg@gmx.com> ---
(In reply to Benoit Rostykus from comment #12)
> AdRoll (the company I work for) just put a $1000 bounty on this bug:

That's quite the bounty.

--
July 04, 2014
https://issues.dlang.org/show_bug.cgi?id=2834

--- Comment #15 from Orvid King <blah38621@gmail.com> ---
Would making all the writeln's in http://dpaste.dzfl.pl/fbb4a15cda14 print out be an acceptable solution to this issue? (that is, making heap-allocated structs call their destructors)

--
July 04, 2014
https://issues.dlang.org/show_bug.cgi?id=2834

David Nadlinger <code@klickverbot.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |code@klickverbot.at

--- Comment #16 from David Nadlinger <code@klickverbot.at> ---
(In reply to Orvid King from comment #15)
> Would making all the writeln's in http://dpaste.dzfl.pl/fbb4a15cda14 print out be an acceptable solution to this issue? (that is, making heap-allocated structs call their destructors)

As far as I can see, this would not necessarily test structs contained in other structs/classes/arrays.

--
July 04, 2014
https://issues.dlang.org/show_bug.cgi?id=2834

Orvid King <blah38621@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |blah38621@gmail.com

--- Comment #17 from Orvid King <blah38621@gmail.com> ---
https://github.com/D-Programming-Language/druntime/pull/864

It's not feasibly possible to call destructors on heap-allocated arrays of structures, however this PR does implement the calling of destructors for structs allocated directly on the heap.

--
July 04, 2014
https://issues.dlang.org/show_bug.cgi?id=2834

--- Comment #18 from Jonathan M Davis <jmdavisProg@gmx.com> ---
(In reply to Orvid King from comment #17)
> https://github.com/D-Programming-Language/druntime/pull/864
> 
> It's not feasibly possible to call destructors on heap-allocated arrays of structures, however this PR does implement the calling of destructors for structs allocated directly on the heap.

As I understand it, it should be possible to call the destructors for structs in arrays if we have the additional type information required for precise heap scanning, but until we add that, we're stuck. But if you can make it so that the destructors get called in other circumstances, that's a great improvement regardless.

--
July 05, 2014
https://issues.dlang.org/show_bug.cgi?id=2834

--- Comment #19 from Orvid King <blah38621@gmail.com> ---
We still wouldn't be able to call the destructors in structs for arrays even with precise heap scanning, because we can't know that each value in the array is actually valid. Take for instance an array of File's, it's not valid to call the destructor of File.init, so we could compare the value of an element of an array of structs to it's init value, but who's to say that element was ever initialized in the first place? How would we detect that?

I think the best thing to do with the arrays of structs that have destructors is to simply make them illegal, and to present as an alternative, an array of a structure that you have defined and has an inner alias this to the original structure, but rather than having a destructor, has a named method that the user would have to call themselves for each element that they know is initialized.

--
July 05, 2014
https://issues.dlang.org/show_bug.cgi?id=2834

Dmitry Olshansky <dmitry.olsh@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dmitry.olsh@gmail.com

--- Comment #20 from Dmitry Olshansky <dmitry.olsh@gmail.com> ---
(In reply to Orvid King from comment #19)
> We still wouldn't be able to call the destructors in structs for arrays even
> with precise heap scanning, because we can't know that each value in the
> array
> is actually valid. Take for instance an array of File's, it's not valid to
> call
> the destructor of File.init, so we could compare the value of an element of
> an
> array of structs to it's init value, but who's to say that element was ever
> initialized in the first place? How would we detect that?

It's perfectly valid to call destructor on T.init. In fact compiler will always do so with stack-allocated instances.

--
July 05, 2014
https://issues.dlang.org/show_bug.cgi?id=2834

Rainer Schuetze <r.sagitario@gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |r.sagitario@gmx.de

--- Comment #21 from Rainer Schuetze <r.sagitario@gmx.de> ---
(In reply to Orvid King from comment #19)
> We still wouldn't be able to call the destructors in structs for arrays even with precise heap scanning
[...]
> How would we detect that?

The array handling in lifetime.d should supply a type info with a destructor that iterates over the elements and calls their destructor. You might have to generate that typeinfo at runtime, though.

--
« First   ‹ Prev
1 2 3