title: Ratchet PHP memory leak
body: <p>I use Ratchet as a socket server for some browser-based game, and I noticed a very weird behaviour. </p>
  
  <p>My application class implements WampServerInterface and I noticed that after 4-5 clients connect and disconnect (via autobahn.js) some memory (about 300KB) remains stuck. Then if another 7-8 clients connect and disconnect the memory usage will not increase. It will increase when 10-12 new clients connect and disconnect, so I have an impression that it reuses memory but still I have a fear that it could cause a memory leak, when many clients connect to the server.</p>
  
  <p>Then I decided to do some testing, I made an application class that implements MessageComponentInterface (so that I can connect with the telnet). Here is the code that launches the server:</p>
  
  <pre><code>&lt;?php
  ini_set('display_errors', 'On');
  
  require 'vendor/autoload.php';
  require 'bootstrap.php';
  
  use Ratchet\Server\IoServer;
  use AsterMedia\Games\Socket;
  
  $server = IoServer::factory(
      new Socket(),
      9090,
      '127.0.0.1'
  );
  
  $server-&gt;run();
  
  ?&gt;
  </code></pre>
  
  <p>My application class is very simple and it looks like this:</p>
  
  <pre><code>    &lt;?php
  
      namespace AsterMedia\Games;
  
      use Ratchet\MessageComponentInterface;
      use Ratchet\ConnectionInterface;
  
      use Symfony\Component\Console\Output\OutputInterface;
  
      class Socket implements MessageComponentInterface {
  
          public function onClose(ConnectionInterface $conn) {
  
              echo "Client disconnected" . $this-&gt;getMemoryUsage() . PHP_EOL;
  
          }
  
          public function onError(ConnectionInterface $conn, \Exception $e) {
  
              echo $e-&gt;getMessage() . PHP_EOL;
          }
  
          public function onOpen(ConnectionInterface $conn) {
  
              echo "Client connected" . $this-&gt;getMemoryUsage() . PHP_EOL;
  
          }
  
          public function onMessage(ConnectionInterface $from, $msg) {
  
              echo $msg . PHP_EOL;
          }
  
          private function getMemoryUsage() {
  
              return sprintf('[Memory usage (currently) %dKB/ (max) %dKB]', round(memory_get_usage(true) / 1024), memory_get_peak_usage(true) / 1024);
          }   
  
  
      }
  </code></pre>
  
  <p>Finally, I made a bash script that connects and disconnects in an endless loop:</p>
  
  <pre><code>    while true
      do
      echo "connect"
      exec 3&lt;&gt;/dev/tcp/127.0.0.1/9090
      exec 3&lt;&amp;-
      echo "disconnect"
      sleep 1
      done
  </code></pre>
  
  <p>After running the bash script, I noticed the same behavior - after a few cycles, the memory usage increases.</p>
  
  <p>Is this issue related to Ratchet (or React) or this is simply PHP's issue? I forgot to mention that I use PHP 5.5.3 with GC enabled.</p>