Running System.gc() on server workflow

I found what sounds like the solution for my issue (server memory consistently showing consumption when nothing is actually running)

This thread discusses running a workflow every hour with an execute function in a KNIME workflow: System.gc()

This thread says you can run garbage collection by using System.gc(); in a Java Edit Variable node.

I’m a little hopeless with Java and I don’t understand how this can be applied in a standalone workflow that could be run every hour.

Does anyone have the Dummies Guide to doing this ?

Hi @zedleb :slight_smile:

Java should clean up memory by itself when it is needed, but if you’d like to give this a try, it should be as simple as running the code exactly as you suggested. Here is an example:

In the resources you link, Scott also pointed out the Run Garbage Collector node in the Vernalis community extension that basically does the same thing.

If you go with the aforementioned workflow, you can simply upload it to your Server and schedule it to run e.g. every hour.

Kind regards

1 Like

That’s great Marvin thanks. I had actually created exactly that variable, I didn’t know that all I had to do was run it :rofl:

Just checked it out on the server which was stuck at 53% (with nothing running), it ran and the result came down to 1%

Question: can this be run safely while other workflows are running or is it better practice to call it at the end of some of our scheduled workflows ?

Yeah, it should run safely at any time. It does consume some CPU time though, and in some cases may halt all executions while it is running. It shouldn’t run longer than around a second for each GB of memory cleaned up, though.

Kind regards