I have installed Ubuntu in VirtualBox and installed a few applications in Ubuntu. But my Windows RAM size is 2 GB. I want to change it to 4 GB RAM. Will doing this erase all the data in Ubuntu?
The hardware resources of a guest OS that is running in a virtual machine are virtual too, not physical. For example an Ubuntu guest OS that uses 2GB or 4GB of RAM gets its RAM from the VirtualBox application which in turn uses some of the physical RAM of the computer that it is running on the same as all other applications in the host OS do. Another consequence of this is that the virtual RAM allocated to the guest OS does not affect the performance of the host OS in any way except when the guest OS is running.