core.exception.InvalidMemoryOperationError@(0)

Vladimir Panteleev via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jan 25 00:53:53 PST 2015


On Sunday, 25 January 2015 at 08:41:25 UTC, Bayan Rafeh wrote:
> The solution was just to remove the "delete a" from the 
> destructor if someone comes across this later. Could someone 
> tell me why though?

The "non-reentrant" bit applies to all GC operations, really - 
not just allocations. Explicit deletions are forbidden as well.

Use of the "delete" keyword is discouraged, and in that context, 
it is also not used in a safe way. By the time B's destructor is 
called, the A instance might have been already collected by the 
garbage collector, causing a double free bug (one of the reasons 
to not use delete).


More information about the Digitalmars-d-learn mailing list