How to set a memory limit?

Just a note that, at least on linux, you could use something like ulimit (from bash), systemd's MemoryHigh and MemoryMax directives, or firejail's --rlimit-as option (if you're sandboxing it anyway). Just wanted to provide additional options in case those are available to you.