title: Signal R Persistant Connection memory Leak
body: <p>I have a product that uses SignalR (the .NET Framework Version) for its communications. In order for it to work everywhere, we offer that customers can talk to the client via a normal Server&gt;Cloud&gt;Client connection or directly via a SelfHosted SignalR connection.</p>
  <p>Everything works fine, except for the fact that it seems that the SelfHosted Connection seems to have a memory leak when sending data directly to the client</p>
  <p><strong>The cloud Connection version is this</strong></p>
  <pre><code>var _connection = new Connection(ServerUrl);
  _connection.Received += OnReceived;
  IClientTransport connectionType;
  var connectionType = new WebSocketTransport();
  _connection.Start(connectionType)
  </code></pre>
  <p>With send from this like this:</p>
  <pre><code>private void HandleResult(HeaderPacket headerPacket)
  {
     _connection.Send(headerPacket); //Send data to Client via Cloud
  }
  </code></pre>
  <p>(above code have no memory leaks)</p>
  <hr />
  <p>The SelfHosted Version is this</p>
  <pre><code>var url = &quot;http://*:8889&quot;;
  using (WebApp.Start&lt;Startup&gt;(url))
  {}
  
      public class Startup
      {
          public void Configuration(IAppBuilder app)
          {
              GlobalHost.Configuration.MaxIncomingWebSocketMessageSize = int.MaxValue;
              app.MapSignalR();
              app.MapSignalR&lt;ServerEndPoint&gt;(&quot;/Server&quot;);
          }
      }
  
  
      public class ServerEndPoint : PersistentConnection
      {
          private void HandleResult(HeaderPacket response)
          {
              var data = JsonConvert.SerializeObject(response);
              Connection.Send(response.ClientConnectionId, data);
          }
  
          protected override Task OnReceived(IRequest request, string connectionId, string data)
          { ... }
      }
  </code></pre>
  <p>It is the
  Connection.Send(response.ClientConnectionId, data);
  Call that makes the memory increase with every call, also with only a single connection.. It should out a few MB and quickly (after 100 calls) it is using 50MB.</p>
  <p>If I comment out the send part as the only thing there is no memory leak (indicating it is not the rest of the code that has the memory leak).</p>
  <p>I've tried to upgrade latest NuGet packages but the leak persists so I assume it must be some odd setting I'm missing :-(</p>