I installed Magento 2.1.8 (lastest version) with sample data on my VPS. My VPS initially had 512Mb. After installation, the home page can be loaded couple of times and crashed completely, mysql service was terminated because of ran out of RAM so upgraded my VPS RAM to 2Gb.
When I ran the command free -m to check how much memory had been used and how much was still available. The first time I checked, it was around 300Mb used but I saw that memory kept adding up each time the page loaded, it added more if I add some items to cart and it never went down. Now it is 825Mb. If I reload the page, it is gonna add more.
There is no traffic at all, just only me testing some basic function on the page. I'm wonderring why it consumes too much RAM and why it never releases any RAM. Will it will release the RAM when reach a certain amount of RAM or just build up like this?
The Magento 2 system requirements recommend a minimum of 2GB RAM: http://devdocs.magento.com/guides/v2.1/install-gde/system-requirements-tech.html
I don't know what your setup is but RAM will be needed for all services being used, e.g. MySQL, PHP, Redis? and webserver (could be php-fpm + nginx). These will all recover memory as they can and you can do some configuration to optimise memory usage but it's unlikely you're going to need to do this if you're just setting up.
512MB RAM is too less for m2. You need at least 2GB for a fresh m2 with sample data.