Bug 11060 – delete gives InvalidMemoryOperationError

Status
RESOLVED
Resolution
INVALID
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-09-17T22:13:00Z
Last change time
2013-09-17T23:22:09Z
Assigned to
nobody
Creator
thelastmammoth

Comments

Comment #0 by thelastmammoth — 2013-09-17T22:13:43Z
class B{ int*a; this(){ a=new int; } ~this(){ version(A1) delete a;//core.exception.InvalidMemoryOperationError ; even though http://dlang.org/deprecate.html#delete doesn't list as deprecated yet version(A2) a.clear;//works even though docs recommends DEPRECATED 'Scheduled for deprecation in December 2012. Please use destroy instead of clear.'; and should appear in http://dlang.org/deprecate.html#delete version(A3) a.destroy;//OK } } void main(){ auto a=new B; }
Comment #1 by maxim — 2013-09-17T22:56:17Z
Please read the spec.
Comment #2 by thelastmammoth — 2013-09-17T23:13:03Z
(In reply to comment #1) > Please read the spec. It would be helpful if you could be more specific. * as I wrote in the bug report, why is 'clear' not deprecated even though spec says it should be by december 2012? (and it's also in several phobos modules) * according to http://dlang.org/memory.html, 'If there is a delete(), there should be a corresponding new()' In my example, there is no new() function, so why does it even compile? * according to Jonathan Davis (see email "allocate array with new"): "No. _Never_ use delete. It's going to be deprecated". * in http://dlang.org/deprecate.html#delete, it says delete will be deprecated at a later time. * a number of phobos modules use delete. So all in all the spec is not very clear to me, and maybe to others as well.
Comment #3 by maxim — 2013-09-17T23:22:09Z
This was discussed really plenty of times - current garbage collector is not reenterable. So, if GC during garbage collection calls destructor, you cannot invoke any operation which directly or indirectly calls the GC. Clear() and destroy() work because they don't call the GC.