I have a 4yr old phone and it's CPU processor can take up to 6GB RAM, but I have the model with 3GB of RAM and it's somewhat slow in doing some tasks that are high demanding. So, after I root the phone using Magisk and use Roehsoft RAM Expander and my SD card to expand it to 6GB RAM, if I unroot my phone back, will the virtual RAM still remain or will it get left behind?
Removing root doesn't change anything that was done with root access, it just removed your ability to make changes to the system partition. You will need to remove any changes done manually before unrooting. Most people in this case had done a nandroid backup prior to the changes/rooting, and then just restore it.
Note that if you unroot, some of those changes or applications may require root access... Removing Magisk, which manages the root access, may cause them to still be installed but not function or only partly work. It is also possible that removing root could render the device unusable.
The recommended way to "unroot" is to flash the device back to stock or restore a pre-root nandroid backup.