January 16, 2011
On Saturday 15 January 2011 20:27:26 %u wrote:
> > Tracking memory in a modern OS is not easy, and this is probably why no one
> 
> wanted to make a statement on what was really happening.
> 
> The issue is that the memory *is* leaking -- it's because the struct destructor is simply not getting called. If I call free() manually, the memory usage decreases normally, so it's not a measurement problem.
> 
> Furthermore, this doesn't seem to be an Array(T)-related bug at all -- it seems that pretty much *any* struct with a destructor will not have its destructor called on exit. In fact, after reading the language specifications, it seems like the glossary contradicts itself: it defines Plain Old Data as referring "to a struct that [...] has no destructor. D structs are POD."
> 
> By definition, if D structs were POD, then they could not have any destructors. It seems like the language contradicts itself, and the compiler only *sometimes* calls struct destructors.
> 
> Any ideas? Is this a bug?
> 
> And thank you for all your great responses! :)

It's probably this bug: http://d.puremagic.com/issues/show_bug.cgi?id=2834

However, there are several bugs relating to destructors, and stuff that ends up on the heap is big problem as far as destructors go IIRC. So, it's definitely a bug.

- Jonathan M Davis
January 17, 2011
On Sat, 15 Jan 2011 23:27:26 -0500, %u <wfunction@hotmail.com> wrote:

>> Tracking memory in a modern OS is not easy, and this is probably why no one
> wanted to make a statement on what was really happening.
>
> The issue is that the memory *is* leaking -- it's because the struct destructor is
> simply not getting called. If I call free() manually, the memory usage decreases
> normally, so it's not a measurement problem.
>
> Furthermore, this doesn't seem to be an Array(T)-related bug at all -- it seems
> that pretty much *any* struct with a destructor will not have its destructor
> called on exit. In fact, after reading the language specifications, it seems like
> the glossary contradicts itself: it defines Plain Old Data as referring "to a
> struct that [...] has no destructor. D structs are POD."

This is definitely a bug.  A struct dtor should be called on scope exit.

That documentation is also out of date.  D1 structs had no destructors or constructors, so it's probably just a stale doc.

I find it very hard to believe that struct dtors are never called.  There must be some situations where they are called, or the feature would not have made it this far without outcry.  The bug referenced by Jonathan is referring to structs not having their dtors called on collection.  But that is a completely different problem.

-Steve
January 18, 2011
> I find it very hard to believe that struct dtors are never called.

Sorry, that part was my bad -- last time I checked, they didn't get called, but maybe my example was too complicated, since they did get called for a *simple* example.

However, here's a situation in which no postblit or destructor is called whatsoever:

import std.stdio;
struct S
{
   this(int dummy) { writeln("ctor"); }
   this(this) { writeln("postblit"); }
   ~this() { writeln("dtor"); }
}
S test(int depth) { return depth > 0 ? test(depth - 1) : S(0); }
int main(string[] argv) { test(3); }
January 18, 2011
On Tue, 18 Jan 2011 01:16:51 +0000, %u wrote:

>> I find it very hard to believe that struct dtors are never called.
> 
> Sorry, that part was my bad -- last time I checked, they didn't get called, but maybe my example was too complicated, since they did get called for a *simple* example.
> 
> However, here's a situation in which no postblit or destructor is called whatsoever:
> 
> import std.stdio;
> struct S
> {
>    this(int dummy) { writeln("ctor"); }
>    this(this) { writeln("postblit"); }
>    ~this() { writeln("dtor"); }
> }
> S test(int depth) { return depth > 0 ? test(depth - 1) : S(0); } int
> main(string[] argv) { test(3); }


That would be bug 3516, wouldn't it?

  http://d.puremagic.com/issues/show_bug.cgi?id=3516

-Lars
January 19, 2011
> That would be bug 3516, wouldn't it?

Huh... yes, it indeed would. Thanks for the link, I couldn't think of the right keywords to search for. :)
1 2
Next ›   Last »