Bug 8875 – core.exception.InvalidMemoryOperationError in case of remove() in Destructors
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2012-10-22T20:37:00Z
Last change time
2012-10-26T22:40:36Z
Assigned to
nobody
Creator
hotcocoamix
Comments
Comment #0 by hotcocoamix — 2012-10-22T20:37:40Z
example code ( no error ):
void main(){
C c;
c = new C(0);
delete c;
}
class C{
static int[int] staticList;
int myint;
this( int x ){
staticList[x] = 1;
myint = x;
}
~this(){
staticList.remove( myint );
}
}
BUT comment out "delete c;" , freeze by end of runtime.
in addition,
code that only refer to staticList did'nt freeze.
Comment #1 by hotcocoamix — 2012-10-25T15:36:03Z
core.exception.InvalidMemoryOperationError
Comment #2 by maxim — 2012-10-26T08:51:43Z
(In reply to comment #0)
> example code ( no error ):
>
> void main(){
> C c;
> c = new C(0);
> delete c;
> }
> class C{
> static int[int] staticList;
> int myint;
>
> this( int x ){
> staticList[x] = 1;
> myint = x;
> }
> ~this(){
> staticList.remove( myint );
> }
> }
>
> BUT comment out "delete c;" , freeze by end of runtime.
>
> in addition,
> code that only refer to staticList did'nt freeze.
AFAIK D garbage collector is non-reenterable. When a program returns from main function and GC collects objects, destructors should not perform gc-related operations because it will result in InvalidMemoryOperationError.
Comment #3 by hotcocoamix — 2012-10-26T15:32:00Z
(In reply to comment #2)
> AFAIK D garbage collector is non-reenterable. When a program returns from main
> function and GC collects objects, destructors should not perform gc-related
> operations because it will result in InvalidMemoryOperationError.
I think non-static destructor must be able to operate static member.
so, GC must has more better Transfer of authority than if(running) .
its possible ?
Comment #4 by maxim — 2012-10-26T22:40:36Z
(In reply to comment #3)
> (In reply to comment #2)
> > AFAIK D garbage collector is non-reenterable. When a program returns from main
> > function and GC collects objects, destructors should not perform gc-related
> > operations because it will result in InvalidMemoryOperationError.
>
> I think non-static destructor must be able to operate static member.
> so, GC must has more better Transfer of authority than if(running) .
> its possible ?
Whether data is static or not does not affect GC behavior on collecting garbage when main function exits.