Your system has run out of Application Memory but plenty of memory?
This is an answer as all the questions are closed. I have a MacBook Air M2 and had this issue and I know my Macs, I had plenty of memory and all running applications basically took none of it.
But I kept getting this error, often when waking from sleep. Actually, *always* when waking from sleep.
One day I saw it - the Screen Saver was peaking at 96Gb (and bright red in Activity Monitor) before it disappeared.
I had the photos screen saver on, I changed it to something else, problem solved. I do have a lot of photos and it was set to random rotation, but I suspect a bug in that screen saver.
So - if you have Out of Application Memory and lots of memory and it's after you open up your Mac - give it a try....
MacBook Air, macOS 12.6