K
K
komarevtsev2016-08-08 14:10:26
css
komarevtsev, 2016-08-08 14:10:26

How to properly clear memory?

I wrote a function to reconnect to the ws channel:

function connect() {
  var ws = new WebSocket('ws://...');

  ws.on('message', function (message) {
    //
  })

  ws.on('close', function () {
    ws.removeAllListeners('message');
    setTimeout(connect, 10000);
  })
}

Even though the on handler is removed, the entire closure still remains in memory. I would like to understand why

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry, 2016-04-10
@dimasmagadan

can be done by standard means:
1 make a menu where the main items will be what is displayed with large buttons
2 child items that will be displayed when hovering below
3 add css, if desired, js

M
Mikhail Osher, 2016-08-08
@miraage

Try ws = null;it in a handler close.

O
OVK2015, 2016-08-08
@OVK2015

Remains because connect is involved in setTimeout.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question