给定以下代码:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var mouseMove = Observable
.FromEventPattern<MouseEventHandler, MouseEventArgs>(
eventHandler => this.MouseMove += eventHandler,
eventHandler => this.MouseMove -= eventHandler);
var mouseMoveSubscription = mouseMove.Subscribe(args =>
{
//Do Something
});
}
}
鉴于我希望订阅遵循 MainWindow 的生命周期,从 mouseMoveSubscription 中处理\取消订阅的正确\最佳位置在哪里。我主要担心的是我不会导致持续超过 Windows 生命周期的内存泄漏。谢谢。