You can force garbage collection in java using jcmd <pid> GC.run
as shown at this StackOverflow link: How do you Force Garbage Collection from the Shell? . I understand that forcing garbage collection is frowned upon, but I was wondering if there was a similar command for golang. Like this question, I would like know if garbage collection can be done from the command line instead of calling Runtime.GC().
Asked
Active
Viewed 962 times
-1

kc123
- 7
-
2No, you would need to set that up yourself. – JimB Apr 30 '20 at 22:52
1 Answers
2
It is not possible to run the GC from the command line. Think that your program is a standalone compiled version. If you need to "force" the GC to run at certain times, I think you could use two formulas:
- In your app, check the existence of a file with inotify. When the file appears, you run the GC
In your app, wait for a signal from the operating system (Linux), such as SIGUSR1, and run the GC. Then you send the signal from the console using:
kill -10 pid
Where pid is the identifier of the running program as it appears in ps -aux

Pablo
- 41
- 2