3

我正在处理 .Net 项目(Windows 服务),我发现内存泄漏。使用 ANTS 内存分析器,我已经确定 - 根本原因是在非托管内存范围内。但我不使用任何 COM/COM+ 或 p/invoke - 纯 .Net(DataAcces - Fluent nHibernate、Automapper、WCF)..

假设是什么原因?我怎样才能找到瓶颈..我对任何经历过并解决过这种问题的经历都感兴趣

更多细节:

  • 我知道对象是如何处理的(并且做得对)
  • 我(几乎)不使用事件
  • 我正在使用计时器
  • 我正在使用多线程(但它相当并行)
  • 我的应用程序不是无状态的 - 我在对象的生命周期中跟踪它们
4

1 回答 1

2

About Memory Leaks

Generally Speaking Memory Leaks still can exist in .net. (Sort of, not all of these are text book memory leaks per se) As in things get stuck in generation 2 garbage collection or when not disposing of object that inherit from IDisposable or for that matter Streams, Events, SQL connections that stay open and mess with you connection pool.While I am not an expert in the matter I will point you to a couple of places that may help you on your quest.

While you are at it Groking the way that garbage collection works helps in this sort of endevor a great deal. Start with something like The Fundementals of Garbage Collection for a general mental picture of just what the heck is going on with all that .NET magic behind the scenes.

On the COM Stuff

Inherent in .NET there are many things that are just simply com and or win32 wrappers calling PInvoke behind the scenes. If gettin down and dirty with insides is what you are wanting then I'd recommend you look at a Decompiler (like IL Spy) where you suspect the leaky code.

Check this out for a deeper discussion on all the wrapper related stuff.
Is .NET A Wrapper Around Win32?

于 2012-05-11T20:49:32.317 回答