简体   繁体   English

Unity容器内存泄漏

[英]Unity Container Memory Leaks

Hi I´m working on a project that uses Enterprice Libraries´s Unity container to resolve dependencies for exception handling, cache, logging and db access but we keep getting a lot of leaked objects into memory. 嗨,我正在一个项目中,该项目使用Enterprice Libraries的Unity容器解析异常处理,缓存,日志记录和数据库访问的依赖关系,但我们不断将大量泄漏的对象存储到内存中。

We are using property injection like this: 我们正在像这样使用属性注入:

[Dependency]
public Database DB
{
  get { return db; }
  set { db = value; }
}
[Dependency]
public ExceptionManager ExceptionMgr
{
  get { return exceptionManager; }
  set { exceptionManager = value; }
}

Some of the object leaked: 一些对象泄漏:

Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSetti Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSetti Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionPolicyData Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionPolicyData
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ReplaceHandlerData Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ReplaceHandlerData
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.WrapHandlerData Microsoft.Practices.EnterpriseLibrary.Common.Configuration.GenericEnumeratorWrapper Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerData Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.WrapHandlerData Microsoft.Practices.EnterpriseLibrary.Common.Configuration.GenericEnumeratorWrapper Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerData Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings
Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheStorageData Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheStorageData

Any general advice on handling dependencies with Unity to avoid object leaks? 关于使用Unity处理依赖项以避免对象泄漏的任何一般性建议?

All the objects you list are part of the configuration system. 您列出的所有对象都是配置系统的一部分。 How are you initializing your container? 您如何初始化容器? Just calling "AddNewExtension()?" 只是调用“ AddNewExtension()?” If so, it's not really a leak, since those objects represent the configuration you loaded. 如果是这样,那实际上不是泄漏,因为这些对象代表您加载的配置。 The configuration source (which is what's holding on to those objects) stays around for the life of the app so that it can watch for, and notify you, of changes in your application. 配置源(保留在那些对象上的资源)在应用程序的生命周期内一直存在,以便它可以监视并通知您应用程序中的更改。

What tools are you running that are telling you they're leaking? 您正在运行的哪些工具正在告诉您它们正在泄漏? And are the leaks growing, or constant? 泄漏在增加还是持续不断? Some details would help narrow down the behavior from "expected" to "whoops actual bug". 一些细节将有助于将行为的范围从“预期的”缩小到“消除实际的错误”。

Also, this is more an Enterprise Library question than a Unity one - Unity itself doesn't leak that I know of. 而且,这比Unity问题更是一个企业库问题-我知道Unity本身不会泄漏。

Are you disposing the Database instance properly? 您是否正确处理了数据库实例? Like for example (using db = new Database()) { .... } ? 例如(使用db = new Database()){....}?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM