How to limit WSL memory usage
1. Create .wslconfig file with the following content
C:\Users\Development\.wslconfig
[wsl2]
memory=4GB
2. Restart the WSL service
  1. Restart-Service LxssManager
3. Verify the memory usage
  1. free --human
              total        used        free      shared  buff/cache   available
Mem:          3.8Gi       100Mi       3.7Gi       0.0Ki        35Mi       3.6Gi
Swap:         1.0Gi          0B       1.0Gi