According to Heroku doc, to avoid garbage, you can provide flags to V8 in your Procfile:
web: node --optimize_for_size --max_old_space_size=460 --gc_interval=100 server.js
However, my app uses foreverjs, and I use the following instruction in the Procfile:
web: ./node_modules/.bin/forever -m 5 server.js
Is there a way to provide flags like --max_old_space_size
or gc_interval=100
and still use foreverjs?
I'm using pm2 not forever but as it seems that forever as this syntax :
usage: forever [action] [options] SCRIPT [script-options]
I would try to put those in the script-options part :
./node_modules/.bin/forever -m 5 server.js --max_old_space_size=460 --gc_interval=100
Either way, I wouldn't force the timing of the gc... The max_old_space_size should be in acordance to the RAM you have available for your node process, and in your case, if your node process take more than ~500M of RAM it should trigger a gc call by himself.