Heisenbug involving Destructors & GC - Help Needed

Brian Schott via Digitalmars-d digitalmars-d at puremagic.com
Fri Jun 26 20:52:00 PDT 2015


On Saturday, 27 June 2015 at 03:44:54 UTC, Temtaime wrote:
> Disagree. Destroy on a pointer calls dtor of a struct.

This is false. The fact that you think that this is true is the 
reason that we want it to be an error

import std.stdio : writeln;
import core.stdc.stdlib : malloc;

private struct S
{
	~this()
	{
		writeln("Destructor call");
	}
}

void main()
{
	S* s1 = cast(S*) malloc(S.sizeof);
	destroy(s1);
	S* s2 = cast(S*) malloc(S.sizeof);
	typeid(S).destroy(s2);
}

Run this program. You'll only see one destructor call.


More information about the Digitalmars-d mailing list