1
Vote

out of memory error

description

My QA dept. has been seeing this error erratically (maybe once per day). Since it is in the constructor, it's not input related. Why would it not occur every time I instantiate my LanguageData?

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
at Irony.Parsing.Construction.ParserStateData.AddItem(LR0Item core)
at Irony.Parsing.Construction.ParserStateData.AddItem(LR0Item core)
at Irony.Parsing.Construction.ParserStateData.AddItem(LR0Item core)
at Irony.Parsing.Construction.ParserStateData.AddItem(LR0Item core)
at Irony.Parsing.Construction.ParserStateData.AddItem(LR0Item core)
at Irony.Parsing.Construction.ParserStateData.AddItem(LR0Item core)
at Irony.Parsing.Construction.ParserStateData.AddItem(LR0Item core)
at Irony.Parsing.Construction.ParserStateData..ctor(ParserState state, LR0ItemSet kernelCores)
at Irony.Parsing.Construction.ParserDataBuilder.FindOrCreateState(LR0ItemSet coreItems)
at Irony.Parsing.Construction.ParserDataBuilder.CreateInitialState(NonTerminal augmentedRoot)
at Irony.Parsing.Construction.ParserDataBuilder.CreateParserStates()
at Irony.Parsing.Construction.ParserDataBuilder.Build()
at Irony.Parsing.Construction.LanguageDataBuilder.Build()
at Irony.Parsing.LanguageData..ctor(Grammar grammar)

comments

rivantsov wrote Sep 16, 2013 at 9:05 PM

hm... have no idea.. can you pls provide more info - maybe share the grammar?

brantheman wrote Sep 24, 2013 at 9:49 PM

I think I was literally out of memory (on my 32bit app). I was creating multiple instances of the grammar (with slight variations in each). Each instance takes about 15MB. Honestly, it's way too large (at 84 bytes per terminal). It shouldn't be that large. There must be a lot of fields on the terminals that mostly go unused. I have restructured my code to not make so many instances of the parser.

In addition, I've been tracking it with the memory profiler. I discovered the CurrentGrammar property (and field) on Grammar. It keeps my most recently created 15MB parser hanging around in memory on a per-thread basis. Ouch! Would it work to just kill that in my personal compilation? After all, we have a Grammar property on BnfTerm. I've worked around this issue by calling "new Grammar()" after I construct mine.

rivantsov wrote Oct 1, 2013 at 5:29 PM

I think CurrentGrammar is used only during Grammar construction (while constructor executes), to support some static methods, and can be cleared at the end of the constructor. And yes, 15MB per grammar seems huge. I don't think it has anything to do with terminals itself, as they basically defined, just something somewhere keeps hanging in memory. I can look at it if you provide me with the grammar, in some way I can compile it locally - with your too specific dependencies cut off, but with reproducible memory trouble.