Search code examples
node.jsstrongloop

Expose garbage collector in a Node.js app with StrongLoop support


We are trying to call the garbage collector into a Node.js application.

In a regular Node.js app, this is quite simple, you only need to run your service with a param:

node -expose-gc script.js

And simply call gc into your code when you want to call the garbage collector:

Global.gc();

But since we are moving to StrongLoop, and we run the app with the slc tool.

The question is: How can i specify the -expose-gc parameter when running the app with slc? Using the next command, the gc() call fails:

slc -expose-gc run script.js 

(and when you exect Global.gc() you get...)
TypeError: Object #<Object> has no method 'gc'

It seems that the run flag is ignored


Solution

  • slc run doesn't pass its arguments to node, so don't use it, just use node. You won't lose anything, there isn't any special stuff slc run does.

    slc run was conceived as a wrapper around common Node.js tools (node, npm, node-inspector, etc.) to simplify interactions for people, so they wouldn't have to learn about multiple tools. It turns out, folks are comfortable with multiple tools, and it sometimes just makes things harder.

    (I'm the slc/strong-cli maintainer, btw.)