I work on a computer with 32GB of RAM using Ubuntu 20.04. I often open some VirtualBox machines and keep a lot of stuff open at once. Sometimes I accidentally fill all the RAM memory on the computer and it freezes, so I need to restart it manually. I don't like the solution of using a lot of swap memory because swap memory is also very slow.
I'd like to find a way of killing the process that is using most of the RAM when I accidentally fill it with multiple opened stuff, just so the system will not freeze. Is there any configuration for doing that? Or should I think about a script that will automatically do that when the RAM memory is close to being completely filled?