By default, Google Compute Engine VPS does not come with any swap space, If your program eat more memory, you can just add swap space instead of increasing RAM.
sudo fallocate -l 2G /swapfile
Create file for swap.sudo chmod 600 /swapfile
Set the necessary permissions.sudo mkswap /swapfile
Make it a swap file.sudo swapon /swapfile
Turn on swapping on the file you created.sudo swapon -s
Check status of swap file.
To make this permanent add this to /etc/fstab
/swapfile none swap sw 0 0
Run sudo vi /etc/fstab
to edit that file. Or use your preferred text editor.
If you need to resize the swap file
sudo swapoff /swapfile
Turn off swapping.sudo fallocate -l 4G /swapfile
Change file size, replace 4G with the size you prefer.sudo mkswap /swapfile
Make it a swap file again.sudo swapon /swapfile
Turn on swapping again.
Source: Badly Wired