用户在使用GIX4某模块的过程中,内存只见加不见减。我们怀疑出现了内存泄漏,所以我花了相当一段时间来进行此问题的排查。
我使用Red Gate公司的产品ANTS Memory Profiler 5进行应用程序的内存进行监视。并在过程中修改程序中出现的一些问题。但是最后留下一个不知道原因的引用,如图1:
图1 泄漏对象引用图
由图中可以看出,Application.Resources永久地引用了临时控件SelectionDataGrid。原因出在DeferredAppResourceReference类的Inflated事件被ResourceReferenceExpression对象引用。经查找相关资料,确定为WPF框架的BUG。该BUG会使内存不断地泄漏。
官方原文:
When a DeferredResourceReference reference is used by a ResourceReferenceExpression class, the internal Inflated event causes a strong reference to be held to the expression. This keeps the whole visual tree from being collected by the Garbage Collector after the references are removed from the tree if the DeferredResourceReference reference is never inflated.
另外,该补丁并不提供下载……汗!
BUG详见:FIX: You may lose system resources during the life of some Windows Presentation Foundation applications。