title: Disposing combined observables from events
body: <p>I'm writing a socket server which should handle every message received from every client connected to it.</p>
  
  <p>All the messages are enqueued in an observable, so it can be subscribed and observed outside.</p>
  
  <p>To ensure that all client socket messages are put on the same observable I've used the following snippet:</p>
  
  <pre><code>private Subject&lt;IObservable&lt;Msg&gt;&gt; _msgSubject;
  public IObservable&lt;Msg&gt; Messages { get; private set; }
  
  public SocketServer()
  {
      // ...
      // Initialization of server socket
      // ...
      _msgSubject = new Subject&lt;IObservable&lt;Msg&gt;&gt;();
      Messages = _msgSubject.Merge();
  }
  
  private void OnNewConnection(ISocket socket)
  {
      var evtObservable = Observable.FromEvent&lt;Action&lt;byte[]&gt;, byte[]&gt;(action =&gt; action.Invoke, h =&gt; socket.OnMessage += h, h =&gt; socket.OnMessage -= h);
  
      _msgSubject.OnNext(evtObservable);
  }
  </code></pre>
  
  <p>Now, I've inspected the (de)allocation of the memory and the problem is that even if the socket is properly closed, there is still references of the relative observable added into the subject; also, the deregistration of the event is never called.</p>
  
  <p>So, here's the question: is there a way to force the removal of the "socket observable" from the subject?</p>
  
  <p>Maybe something to trigger the OnComplete of the socket observable should do the job, but how?</p>