Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memory leak in CLR classes

Tags:

.net

clr

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

like image 425
user626528 Avatar asked Jan 06 '12 12:01

user626528


People also ask

What is the main cause of memory leaks?

DEFINITION A memory leak is the gradual deterioration of system performance that occurs over time as the result of the fragmentation of a computer's RAM due to poorly designed or programmed applications that fail to free up memory segments when they are no longer needed.

What is memory leak with example?

The memory leak would occur if the floor number requested is the same floor that the elevator is on; the condition for releasing the memory would be skipped. Each time this case occurs, more memory is leaked. Cases like this would not usually have any immediate effects.

What are the types of memory leaks?

There are two types of memory leaks: apparent and subtle. An apparent memory leak is a chunk of heap memory that's never referred from active memory, a subtle leak is memory that is still referred to but shouldn't be, i.e. a hash or dynamic array holds the references.


1 Answers

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

like image 125
user626528 Avatar answered Oct 23 '22 05:10

user626528