天天看點

WPF架構的記憶體洩漏BUG

   使用者在使用gix4某子產品的過程中,記憶體隻見加不見減。我們懷疑出現了記憶體洩漏,是以我花了相當一段時間來進行此問題的排查。

    我使用red gate公司的産品ants memory profiler 5進行應用程式的記憶體進行監視。并在過程中修改程式中出現的一些問題。但是最後留下一個不知道原因的引用,如圖1:

WPF架構的記憶體洩漏BUG

圖1 洩漏對象引用圖

    由圖中可以看出,application.resources永久地引用了臨時控件selectiondatagrid。原因出在deferredappresourcereference類的inflated事件被resourcereferenceexpression對象引用。經查找相關資料,确定為wpf架構的bug。該bug會使記憶體不斷地洩漏。

    官方原文:

when a <b>deferredresourcereference</b> reference is used by a <b>resourcereferenceexpression</b> class, the internal <b>inflated</b> 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 <b>deferredresourcereference</b> reference is never inflated.

    另外,該更新檔并不提供下載下傳……汗!

繼續閱讀