Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

_rt_finalize access violations while allocating an object.

Moderators: kris

Posted: 01/07/08 06:51:27

I've been getting strange access violations when trying to create a new object. I checked in ddbg and had this error : Unhandled Exception: EXCEPTION_ACCESS_VIOLATION(0xc0000005) at _rt_finalize (0x005d0703) thread(4092)

Within the loop where this happens it happens after 619 iterations, if I call GC.collect() while inside the loop (during each iteration) it happens after 71 iterations. It happens at this line : section = new MapSection?(); and it happens before the constructor is called.

The program itself only has allocated about 20MB of memory and I have a lot physical memory left so I don't think I am running into any sort of memory issue. It just seems to be a problem when the gc runs.

I have moved various allocations around and it does effect when the problem occurs, for instance allocating one object before the loop moves the point of failure to 84 iterations.

Author Message

Posted: 01/07/08 08:32:56

Could you please post your sample code? I would recommend creating a ticket too to make sure this is checked properly.

Posted: 01/07/08 21:10:53

Unfortunately its spread across 3 or 4 modules and the datafile is about 500KB in size. I will try to make an example program and see if I can get the error to occur. There are a lot of references being shifted around though, so if I can't get a simpler program should I just post all the snippets I think are relevant to this thread?

Posted: 01/07/08 22:20:41

I looked at this once before regarding a similar error brought up in chat. The only way I can conceive of this occurring is if a class reference ends up pointing to something other than a valid class instance and then delete is called on that reference. The most likely way this would happen is via an attempted double-deletion of an object through two separate references. However, if you can provide information that points to an implementation bug in the runtime then I'd be happy to fix it. I haven't been able to find anything just by examining the code.

Posted: 01/07/08 22:54:06

Hrm.. perhaps something like this is happening. Within the code I do shuffle around a lot of references, I have an inner loop that creates new objects then passes that reference to an ArraySeq? but it sets the reference within the loop to null something like this :

simpleClass test = null; ArraySeq?!(simpleClass) store = new ArraySeq?!(simpleClass); for(int i = 0; i<10000000;i++) {

simpleClass test2 = new simpleClass(i); test = test2; store.append(test); test2 = null; Stdout("Index ")(i)("\n")(m );

}

Atleast its somewhat similar though the above code works fine. Perhaps its too much java programing in me but I've grown used to setting references to null once they aren't needed as an extra hint to the GC that the memory can be reclaimed. I will try and get the program as small as possible and see if I can get a reproducable error in a code chunk that can be posted here. One big hurdle is that this is in XML processing code so Mango is involved as well so I wouldn't discount there being a problem in there somewhere. The main things I do know is that its reproducable with the code I have, and it happens in a consistent place in the garbage collector. If I disable the garbage collector it still throws an exception but I think its in a different place in the code, I'll have to look tonight. I'll try to take out the lines that specifically null the inner reference and see if that helps.

One thing that I did think was odd was that it happens when new is called.. I guess it crosses a threshold of some sort and decides to run the GC in the same spot every time. Is there a way to manipulate the threshold somehow that might give some ideas on what would be happening?

Posted: 01/08/08 16:23:20

A little update, as I have been paring down the code into something that will fit in the forums I have noticed that as I removed some of the imports I didn't think were important it changes the behavior and location of the access violations I get. At times its _rt_finalize and sometimes its mallocNoSynch that has the error. I will have to look closer but it might be the unittests are affecting something. Hopefully I will have more time tonight to look at it.