开发者

Unity Framework memory concern

I am using Microsoft.Practices.Unity framework 1.2 and I can see the memory usage dramatically increasing over time. I've been watching the Garbage Collector heap sizes for Gen 0, 1 and 2 and Objects seems to be continuously promoted to Gen 2 where they stay and get older and older without been claimed by the GC.

Is there some tuning I could do for avoiding this excessive memory consumption开发者_运维技巧?


How do you know it's due to unity framework? It's possible your injected instances are not being disposed properly. I suggest RedGate Memory Profiler as it will tell you exactly what is not being collected. Memory leaks are a PITA and i've been dealing with them for the last 2 weeks.

Event handlers are usually the cause of these types of issues. Make sure you manually remove all event handlers.

I've found that the GC is not as great at cleaning things up as you might have thought.


If objects are migrating to Gen 2, that means they're still live. Make sure your classes implement IDisposable and that they invoke Dispose() on any references they contain. One way to do this automatically (if you're using C#) is to wrap references in a using block. The references will automatically be disposed of at the end of the block.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜