how to debug memory errors

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Nov 7 19:27:32 PST 2016


On 11/6/16 10:57 PM, Era Scarecrow wrote:
> On Monday, 7 November 2016 at 02:22:35 UTC, Steven Schveighoffer wrote:
>> OP: it's not legal to destroy or even access GC allocated members in a
>> destructor. The GC may have already destroyed that data. I would
>> recommend printing the stack trace when you get the exception, and
>> figure out where the culprit is.
>
>  Err.... that makes no sense... If that's the case why have a destructor
> at all?

To free non-GC resources.

http://dlang.org/spec/class.html#destructors

"Furthermore, the order in which the garbage collector calls destructors 
for unreference objects is not specified. This means that when the 
garbage collector calls a destructor for an object of a class that has 
members that are references to garbage collected objects, those 
references may no longer be valid. This means that destructors cannot 
reference sub objects."

-Steve


More information about the Digitalmars-d-learn mailing list