On 1/31/16 3:15 PM, Matt Elkins wrote:
On Sunday, 31 January 2016 at 20:11:07 UTC, Matt Elkins wrote:
On Sunday, 31 January 2016 at 20:10:03 UTC, Matt Elkins wrote:
On Sunday, 31 January 2016 at 20:07:26 UTC, Steven Schveighoffer wrote:
What is likely happening is that ptr is already collected, and you
are invalidly attempting to re-free it.

The GC can collect this memory even though there is still an
outstanding root-reachable pointer to it?

Or maybe it isn't root-reachable?

No, it is still present even if root-reachable:

[code]
unittest
{
     import std.algorithm;

     int* x;
     {
         auto map = new UniquePtr!int[1];
         auto uniqueX = UniquePtr!int(5);
         x = uniqueX.get();
         map[0] = move(uniqueX);
     }
}
[/code]

[output]
core.exception.InvalidMemoryOperationError@src\core\exception.d(679):
Invalid memory operation
----------------
Program exited with code 1
Made 632560 for this 18FD90
Disposing null for this 18FD70
Disposed null for this 18FD70
Disposing null for this 18FD90
Disposed null for this 18FD90
All unit tests have been run successfully.
Disposing 632560 for this 632550
[/output]

Oh, nevermind. This is actually simpler.

You can't do memory operations inside a destructor during collection. I forgot about that.

But the rule I stated is still in force.

-Steve

Reply via email to