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 /swapfileCreate file for swap.sudo chmod 600 /swapfileSet the necessary permissions.sudo mkswap /swapfileMake it a swap file.sudo swapon /swapfileTurn on swapping on the file you created.sudo swapon -sCheck 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 /swapfileTurn off swapping.sudo fallocate -l 4G /swapfileChange file size, replace 4G with the size you prefer.sudo mkswap /swapfileMake it a swap file again.sudo swapon /swapfileTurn on swapping again.
Source: Badly Wired