I have the following code in a WPF application using Reactive Extensions for .NET:
public MainWindow()
{
InitializeComponent();
var leftButtonDown = Observable.FromEvent<MouseButtonEventArgs>(this, "MouseLeftButtonDown");
var leftButtonUp = Observable.FromEvent<MouseButtonEventArgs>(this, "MouseLeftButtonUp");
var moveEvents = Observable.FromEvent<MouseEventArgs>(this, "MouseMove")
.SkipUntil(leftButtonDown)
.SkipUntil(leftButtonUp)
.Repeat()
.Select(t => t.EventArgs.GetPosition(this));
moveEvents.Subscribe(point =>
{
textBox1.Text = string.Format(string.Format("X: {0}, Y: {1}", point.X, point.Y));
});
}
Will there be a steady increase of memory while the mouse is moving on this dialog?
Reading the code, I would expect that the moveEvents observable will contain a huge amount of MouseEventArgs after a while? Or is this handled in some smart way I'm unaware of?
No, there shouldn't be a steady increase in memory usage - why would there be? The events are basically streamed to the subscriber; they're not being buffered up anywhere.
The point of Rx is that events are pushed to the subscriber, who can choose what to do with them. It's not like adding events to a list which is then examined later.
(There are ways of buffering events in Rx, but you're not using them as far as I can tell.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With