Why is it a memory ERRO.

Mike Parker via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jan 29 05:22:07 PST 2016


On Friday, 29 January 2016 at 12:43:53 UTC, Dsby wrote:
> the Code:

> 	~this(){
> 		GC.free(by.ptr);
> 		by = null;
> 		writeln("free");
> 	}

Your problem is probably that you are calling GC.free in the 
destructor. Don't do this. You don't need to call GC.free at all. 
The GC will collect both your object instance and the memory you 
allocated with new. Never, ever, manipulate GC memory in the 
destructor of a GC-managed object.


More information about the Digitalmars-d-learn mailing list