core.exception.InvalidMemoryOperationError

Joakim via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 11 04:43:42 PDT 2014


On Thursday, 10 July 2014 at 15:36:53 UTC, francesco cattoglio 
wrote:
> A code I'm working on stops working and starts printing an 
> infinite loop of
> core.exception.InvalidMemoryOperationError
> to the command line output. The code is quite complex and the 
> bug seems to present itself almost in random situation so I 
> would like to try to understand the issue better before looking 
> for the wrong line of code hiding somewhere. I've read it might 
> be that something is trying to allocate during a destructor 
> call, but it sounds really strange to me that there's a 
> neverending amount of exceptions being thrown. This is the 
> first exception being thrown (nothing is thrown before the 
> infinite loop begins).
>
> Anyone has suggestions/ideas/heard of a similar stuff before?

If you look at the source for the garbage collector, the only 
place that error is called is if the gc is trying to malloc or 
execute other memory operations while the collector is running.  
I ran across this myself because an assert was getting triggered 
in a destructor.  Since an assert tries to malloc and the 
destructor is called by the GC, I got an 
InvalidMemoryOperationError which swallowed up the message from 
the original assert.

By putting printfs in the code path in druntime, I was able to 
track it down to that destructor, otherwise I had no idea where 
the invalid memory error was getting triggered.  You can probably 
do the same, but you can be sure it's a GC issue, and I would 
guess tied to allocating in a destructor (unless you happen to be 
calling InvalidMemoryOperationErrors somewhere in your own code 
or some library that you're using, which is unlikely).


More information about the Digitalmars-d-learn mailing list