note that in my case with 16GB of RAM I don’t need a swap space, the memory barely fills up to 50% when using Android Studio, it depends what you are doing, for example heavy code compilation and Finite Element Analysis could demand as more memory as you can load the machine
in case you run out of physical RAM without a swap the system just crashes, the same also happens if the swap too is full
in order to save space you can avoid making a swap, the strategy is to start with a swap and watch the system monitor while doing the heaviest work and if the RAM never goes above 75% you can turn it off and delete the swapfile and make a new one if you run into problems
in case you want to hibernate the system you need a swap space larger than your RAM, you can’t avoid it