Please help with GC exception!

Gor Gyolchanyan gor.f.gyolchanyan at gmail.com
Wed May 9 08:28:30 PDT 2012


I have a structure:

private struct Block
{
	this(size_t n) { /* allocate n bytes with GC.malloc */ }
	this(this) { /* deep-copy the bytes */ }
	~this() { /* deallocate them with GC.free */ }
}

And a class:

final class Region
{
	private Block _block;
	alias _block this;
}


This setup allows me to have memory regions, reallocation of which
will never invalidate pointers, because thanks to Region class no-one
holds a direct pointer to the memory.
The problem is, that I get a
core.exception.InvalidMemoryOperationError when my program ends.

shared static ~this() { import core.thread;
Thread.sleep(dur!`seconds`(1)); } // The error message still showed up
after a delay, so it had to be at the process termination
When I delete the Region object with "clear", the error diappears.
Disabling the GC or forcing a collection before the 1-second sleep
doesn't do anything: I still get the error after the 1-second sleep.
The only way to stop the error, besides manually deleting the object
is the remove the deallocation from the Block's destructor.

Can somebody please help me fix this problem?

-- 
Bye,
Gor Gyolchanyan.


More information about the Digitalmars-d mailing list