Leak in RuntimeBinder when using “dynamic” keyword with __ComObject

后端 未结 2 1008
自闭症患者
自闭症患者 2021-01-06 04:20

Does anybody know if there is a way of preventing a memory leak in RuntimeBinder when using \"dynamic\" keyword with __ComObject instances in C#?

I got the following

相关标签:
2条回答
  • 2021-01-06 05:06

    The solution in my case was to replace:

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

    with:

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

    The memory leak no longer occurs having the workaround applied.

    0 讨论(0)
  • 2021-01-06 05:12

    I had a similar problem: Using "dynamic" caused a memory leak.

    I solved this in the following way:

    using (dynamic attr = curve.Attributes)
    {
      if (attr != null)
        return attr.InternalLabel;
    }
    
    0 讨论(0)
提交回复
热议问题