Note that there are some explanatory texts on larger screens.

plurals
  1. PO.NET Rx - ReplaySubject buffer size not working
    text
    copied!<p>I've been using .NET Reactive Extensions to observe log events as they come in. I'm currently using a class that derives from IObservable and uses a ReplaySubject to store the logs, that way I can filter and replay the logs (for example: Show me all the Error logs, or show me all the Verbose logs) without losing the logs I've buffered.</p> <p>The problem is, even though I've set a buffer size on the subject:</p> <pre><code>this.subject = new ReplaySubject&lt;LogEvent&gt;(10); </code></pre> <p>The memory usage of my program goes through the roof when I use OnNext to add to the observable collection on an infinite loop:</p> <pre><code>internal void WatchForNewEvents() { Task.Factory.StartNew(() =&gt; { while (true) { dynamic parameters = new ExpandoObject(); // TODO: Add parameters for getting specific log events if (this.logEventRepository.GetManyHasNewResults(parameters)) { foreach (var recentEvent in this.logEventRepository.GetMany(parameters)) { this.subject.OnNext(recentEvent); } } // Commented this out for now to really see the memory go up // Thread.Sleep(1000); } }); } </code></pre> <p>Does the buffer size on ReplaySubject not work? It doesn't seem to be clearing the buffer when the buffer size is reached. Any help much appreciated!</p> <p>UPDATE:</p> <p>I add subscribers like this (Is this wrong?):</p> <pre><code>public IDisposable Subscribe(IObserver&lt;LogEvent&gt; observer) { return this.subject.Subscribe(observer); } </code></pre> <p>...which is called like:</p> <pre><code>// Inserts into UI ListView this.logEventObservable.Subscribe(evt =&gt; this.InsertNewLogEvent(evt)); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload