ViewLoadedManager Not Releasing Views When Closed

Topics: Issues / bugs
Apr 23, 2014 at 8:51 PM
I am using ANTS Memory Profiler to search for memory leaks in my application, which makes extensive use of Catel for MVVM. I am finding that whenever I open and close a window that derives from DataWindow, the window is not garbage collected. ANTS shows the following chain of objects holding a reference to the window:

[LogicBase._viewLoadedManager] - >
[Catel.MVVM.Views.ViewLoadedManager._viewElements] ->
[System.Collections.Generic.List<Views.WeakViewInfo>:_items] ->
[Catel.MVVM.Views.WeakViewInfo[]] ->
[Catel.MVVM.Views.WeakViewInfo.<Action>k__BackingField] ->
[System.Action (this as Delegate)._target] ->
[Catel.MVVM.Providers.WindowLogic (this as LogicBase).<TargetView>k__BackingField] ->
[MyWindow (which derives from DataWindow]

This is the only chain holding the window. I get this same chain no matter which window I open and close. I have tried creating a 2nd and 3rd snapshot in ANTS after closing the window to force the GC to collect again, but I still see these windows held in memory by the ViewLoadedManager. When I debug my app, I can see that the window's view model is getting closed (by overriding the ViewModel's Close method and setting a breakpoint), and that the window is getting closed. Some windows are opened with ShowDialog, some with Show.

By looking at the chain above, it appears that the ViewLoadedManager is trying to hold a weak reference to the window's WindowLogic, but it seems that reference is actually strong??

I have also seen this with UserControls - the exact same chain except that the 2nd to last item is UserControlLogic instead of WindowLogic.

This is using a Catel development build downloaded on 4/17.
Apr 23, 2014 at 8:52 PM
It should use weak references in the ViewLoadedManager. I will look into this. Can you please create an issue in the official issue tracker?
Apr 23, 2014 at 9:33 PM
Thanks for the quick reply, Geert. Issue created: