UWP compiled binding x:Bind produces memory leaks

前端 未结 2 1697
后悔当初
后悔当初 2021-02-02 11:25

While developing UWP application I recently found quite a few memory leaks preventing my pages from being collected by GC. I have a ContentPresenter on my page like:

<         


        
2条回答
  •  长情又很酷
    2021-02-02 11:53

    I have created bug on Microsoft connect because of this issue.

    https://connect.microsoft.com/VisualStudio/feedback/details/3077894/memory-leaks-in-c-uwp-apps-using-compiled-x-bind-bindings

    Work around for this issue is to explicitly call Bindings.StopTracking() at page Unloaded event handler. It's because compiled bindings doesn't use "weak event" pattern and does subscribe to PropertyChanged event of INotifyPropertyChanged directly. It's a cause of memory leak. To unsubscribe events you can call Bindings.StopTracking(). Compiled bindings code doesn't call it automatically.

提交回复
热议问题