stockfish.js
stockfish.js copied to clipboard
Memory cannot be freed in nodejs
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.
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.