Clickbait version: Increase your server’s system memory for free! 😀
Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space.[src]
Note: Not recommended to be used in production environment. Swap space is very slow compared to physical memory and can seriously affect your application performance.
It’s fairly common to run into “System.OutOfMemoryException” if you are running a memory heavy application or multiple applications on a remote server. To mitigate this issue you can simply create a Swap space for your server and use your disk space as system memory, this will be a little slower but you wouldn’t have to upgrade your server to higher memory one if you just need some MBs of extra ram or maybe need to perform a single task which needs some extra memory.
To enable 2GB of swap space use the following commands
SWAPFILE=/var/swapfile SWAP_MEGABYTES=2048 sudo /bin/dd if=/dev/zero of=$SWAPFILE bs=1M count=$SWAP_MEGABYTES sudo /bin/chmod 600 $SWAPFILE sudo /sbin/mkswap $SWAPFILE sudo /sbin/swapon $SWAPFILE