Shutdown your running wsl.

wsl --shutdown

Going to c:\users*your your profile name* and creating a .wslconfig file or do it via powershell ;-)

notepad "$env:USERPROFILE/.wslconfig"
[wsl2]
memory=4GB # Limits VM memory in WSL 2 to 4 GB
processors=5 # Makes the WSL 2 VM use two virtual processors
swap=0
localhostForwarding=true

After that start Powershell with admin permissions, restart WSL2 by typing:

Restart-Service LxssManager

Drop Cache variable for WSL

create this alias at the end of your ~/.bashrc file

alias drop_cache="sudo sh -c \"echo 3 >'/proc/sys/vm/drop_caches' && swapoff -a && swapon -a && printf '\n%s\n' 'Ram-cache and Swap Cleared'\""

and run the following in your shell to setup the alias

source ~/.bashrc

then you can run the drop_cache command when you need it.

You can run it manually when you notice high memory usage or you can try to create a crontab job.