问题
I have a memory leak and traced it to this field inside CLR:
Microsoft.CSharp.RuntimeBinder.RuntimeBinder.s_instance.m_semanticChecker.globalSymbolContext.GlobalSymbols.tableGlobal.dictionary
It can be viewed in debugger using this specification:
((Microsoft.CSharp.RuntimeBinder.Semantics.LangCompiler)(Microsoft.CSharp.RuntimeBinder.RuntimeBinder.s_instance.m_semanticChecker)).globalSymbolContext.GlobalSymbols.tableGlobal.dictionary
During execution of application, this dictionary indefinitely grows.
Any ideas, what exactly this field is used for, and why it can grow?
UPD there is no dynamic creation of types, at least in my code
回答1:
The best answer I've found so far:
The problem happens somewhere around Excel VSTO Range.Style property (it uses dynamic data type).
Every time this piece of code
range.Style == null
runs, it makes the binder consume some more memory.
But if I rewrite this code like this
(Style)range.Style == null
then the problem disappears.
UPD reported this to Microsoft https://connect.microsoft.com/VisualStudio/feedback/details/861770/memory-leak-when-using-excel-add-in-api#tabs
来源:https://stackoverflow.com/questions/8757785/memory-leak-in-clr-classes