Hi @NancyW,
At the Yocto project documentation the requirements are at least 8GB of RAM in this case assigned to your virtual machine, so I cannot ensure it will work.
I can suggest is to set BB_NUMBER_THREADS and PARALLEL_MAKE this to make the build use lower resources of your machine (it will include cores).
Just add this lines to your file [your_yocto_build_dir]/conf/local.conf
BB_NUMBER_THREADS = "2"
PARALLEL_MAKE = "-j 2"
And change the number 2 for the number that fits to your system. Remember, lower number slow down the Yocto building. Higher number increase Yocto build but can starve all other process in your machine.
After the change local.conf, move to Yocto base dir and run command source setup-environment ./your_build_folder