std.container.Array/RefCounted(T) leaking memory?

Steven Schveighoffer schveiguy at yahoo.com
Mon Jan 17 05:02:20 PST 2011


On Sat, 15 Jan 2011 23:27:26 -0500, %u <wfunction at 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


More information about the Digitalmars-d-learn mailing list