title: Ratchet + Symfony 3.4 - Release memory
body: <p>I'm trying to implement chat for my existing Symfony 3.4 app.</p>
  
  <pre><code>   $server = IoServer::factory(
          new HttpServer(
              new WsServer(
                  $this-&gt;chatManager
              )
          ),
          $this-&gt;webSocketPort
      );
      $server-&gt;run();
  </code></pre>
  
  <p>In my <code>chatManager</code> I'm accessing DB via DQL. First thing I found that Symfony can not detach entities by itself so I added</p>
  
  <p><code>$this-&gt;em-&gt;clear();</code></p>
  
  <p>in the end of each method where I did use entities.</p>
  
  <p>Now, here is what I have in my <code>chatManager</code></p>
  
  <pre><code>protected function sendMessage(ConnectionInterface $connection, $message): ConnectionInterface
  {
      $context[] = 'chat';
  
      echo $this-&gt;getMemoryUsage() . PHP_EOL;
  
      return $connection-&gt;send(
          $this-&gt;serializer-&gt;serialize($message, 'json', SerializationContext::create()-&gt;setGroups($context))
      );
  }
  
  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>I notice that memory do not release on it's own. It is just growing all the time until it reach some value, after that all requests I'm trying to do via websocket connection falling with error </p>
  
  <p><code>SQLSTATE[HY000]: General error: 2006 MySQL server has gone away</code></p>
  
  <p>What can I do? Thanks.</p>