stockfish.js icon indicating copy to clipboard operation
stockfish.js copied to clipboard

Memory cannot be freed in nodejs

Open zyc9012 opened this issue 7 years ago • 1 comments

I create a stockfish() instance for each game on my server (nodejs), the memory was growing larger and larger when opening new games, but didn't go down when a game was destroyed.

I made a small experiment:

const stockfish = require('stockfish')
const readline = require('readline')

let s = null
const rl = readline.createInterface(process.stdin, process.stdout)
rl.setPrompt('> ')
rl.prompt()
rl.on('line', line => {
  rl.prompt()
  s = stockfish()
  s.onmessage = line => {
    console.log(line)
  }
  s.postMessage('quit')
  s.onmessage = null
  s = null
  global.gc()
}).on('close', () => {
  process.exit(0)
})

Each time I press enter, the memory increases by ~30MB, the memory doesn't go down even if I do manual GC (node --expose-gc test.js), sending quit command does not work either.

zyc9012 avatar Apr 19 '18 02:04 zyc9012

Hey, Not sure if you are still stuck on this problem but if anyone else is having a similar issue then you can try putting the stockfish function in a workerpool worker thread and terminating it after you are done using that particular stockfish instance.

michaldobiezynski avatar Jul 31 '21 10:07 michaldobiezynski