Memory leak in CLR classes

和自甴很熟 提交于 2019-12-12 11:25:39

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!