【问题标题】:Multiple Assembly.Load(Byte[]), same instance or leak?多个 Assembly.Load(Byte[]),相同的实例或泄漏?
【发布时间】:2009-10-12 12:50:10
【问题描述】:

当我使用包含相同程序集的 Byte 数组多次调用 Assembly.Load(Byte[]) 时会发生什么?

每次调用都会获得相同的 Assembly 实例吗?

同一个程序集在应用域内多次加载???

【问题讨论】:

  • 您实际上会泄漏。我在 2006 年设计的一个服务应用程序就是使用这种方法。由于 Assembly.Load() 的原因,我们不得不每周日重新启动它,因为它占用了 4Gb RAM 和 8Gb 分页。
  • 从技术上讲,这当然不是泄漏。但是,将多个 Assembly 实例加载到 AppDomain 中是没有意义的——您很可能只使用一个,而所有其他实例都只是在消耗服务器内存。

标签: c# assemblies appdomain assembly-resolution


【解决方案1】:

每次调用都会得到一个新的 Assembly 对象,请阅读documentation,在结尾处有一条注释:

“请注意,此方法重载始终会创建一个具有自己映射的新 Assembly 对象。”

【讨论】:

  • 谢谢,我错过了小便条。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-29
  • 1970-01-01
  • 1970-01-01
  • 2015-10-21
  • 2012-08-24
相关资源
最近更新 更多