Leak in RuntimeBinder when using a "dynamic" keyword with __ComObject

Does anyone know if there is a way to prevent a memory leak in RuntimeBinder by using a "dynamic" keyword with __ComObject instances in C #?

I got the following code:

var t = Type.GetTypeFromCLSID(new Guid("BB06C0E4-D293-4f75-8A90-CB05B6477EEE"));
while (true)
{
    dynamic o = System.Activator.CreateInstance(t);
    Marshal.ReleaseComObject(o);
}

This is a leak of instances of the LocalVariableSymbol class (and another from the Microsoft.CSharp.RuntimeBinder.Semantics namespace).

Replacing "dynamic" with "object" ie:

    object o = System.Activator.CreateInstance(t);

fixes the leak, but I would prefer to continue to use dynamic (real code is much more complicated and uses "dynamic").

I know that singleton RuntimeBinder caches data, and this causes a leak, but do you know if there is a way to clear the cache, etc.?

Many thanks!


Related questions:

:

+4
2

:

dynamic o = System.Activator.CreateInstance(t);

:

object o = System.Activator.CreateInstance(t);
dynamic d = o;

.

+4

: "dynamic" .

:

using (dynamic attr = curve.Attributes)
{
  if (attr != null)
    return attr.InternalLabel;
}
0

Source: https://habr.com/ru/post/1612585/


All Articles