title: Why does memory used constantly increase in my simple Javascript websocket application?
body: <p>I am having a problem with websocket in Javascript.
  Memory consumption is increasing constantly and I just don't understand why.</p>
  
  <p>My websocket server sends out around 1KB of data per second and it seems like the memory consumed is increasing at the same rate.</p>
  
  <p>If I open up Chrome task manager I can see that the memory consumed by my tab increase constantly. It seems to be the same problem with Internet Explorer.</p>
  
  <p>I have based my code on the example found at this page: <a href="https://www.tutorialspoint.com/html5/html5_websocket.htm" rel="nofollow noreferrer">https://www.tutorialspoint.com/html5/html5_websocket.htm</a></p>
  
  <p>This problem seems to be somewhat similar, but I still don't understand what the problem is. 
  <a href="https://stackoverflow.com/questions/37689162/memory-leak-in-chrome-with-websockets">Memory leak in Chrome with Websockets</a></p>
  
  <p>What am I doing wrong?</p>
  
  <p>Refreshing the web page do release the memory but there must be another way...</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;html&gt;
  &lt;head&gt;
    &lt;script type="text/javascript"&gt;
      var systems = {};
       function WebSocketTest()
       {
          if ("WebSocket" in window)
          {
  
             // Let us open a web socket
             var ws = new WebSocket("ws://192.168.1.1:8081/websocket");
  
             ws.onopen = function()
             {
                // Web Socket is connected, send data using send()
                var subscribe = {};
                var request = {};
                request["test"] = "1";
                subscribe["subscribe"] = request;
                ws.send(JSON.stringify(subscribe));
                //alert("Message is sent...");
             };
  
             ws.onmessage = function (evt)
             {
                var received_msg = evt.data;
                var obj = JSON.parse(received_msg);
                var samples = obj.samples;
                delete samples;
                delete obj;
                delete receieved_msg;
  
             };
  
             ws.onclose = function()
             {
                // websocket is closed.
                alert("Connection is closed...");
             };
  
             window.onbeforeunload = function(event) {
                socket.close();
             };
          }
  
          else
          {
             // The browser doesn't support WebSocket
             alert("WebSocket NOT supported by your Browser!");
          }
       }
    &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
       &lt;a href="javascript:WebSocketTest()"&gt;Run WebSocket&lt;/a&gt;
    &lt;/div&gt;
    &lt;/body&gt;
    &lt;script&gt;
  
    &lt;/script&gt;
    &lt;/html&gt;
  </code></pre>