How to Reduce Memory (RAM) Consumes in WSL 2

In some cases, you want to configure or limit the memory (RAM) for a WSL instance. By default, WSL will take 50% of the host memory. You can check how much memory and swap space are allocated to WSL using the free command from within a WSL distribution: