What does that look like when it happens? I'd like to know what to look for on my machine.
The symptom of RAM starvation is generally an increasing lack of responsiveness to user interaction (e.g. text input) especially when switching between applications, but also when moving between documents in the same applications (e.g. switching between browser tabs).
Opening new applications may result in "beach balls" (the rotating colour wheel cursor) and long wait times.
Some applications may stop responding, which can be "remedied" by option-cmd-escape and force-quitting an unresponsive application.
Eventually, the machine can just lock up completely (no cursor or keyboard response), requiring a hard power down (pressing the power button until the machine turns off). With most applications, you won't lose data, but it's best avoided.
Some people claim they've never had this happen on their Mac; my experience is that if you have a lot of apps & browser tabs open, that it's pretty easy to crash macOS. I also find that my M1 Max MBP does a "quiet reboot and restore" every so often when it's sleeping because of some rogue process causing a kernel panic - I think this is probably related to connected peripherals more than anything else.
It's a good practice to monitor your RAM usage and which processes are using it. This can be a relatively complex topic because there are lots of different metrics available. This article is an example of some explanations:
https://eclecticlight.co/2022/08/13/activity-monitor-meanings-and-misleadings/#:~:text=Real Memory is physical memory,is shared with other processes.
In Activity Monitor you can get an overview in the "memory" tab, and individual process metrics to see if any individual process is hogging memory, or increasing memory usage, which might indicate a "memory leak" in an application.
The overview and the simple memory pressure "colour graph" should give you an idea if you need to start some remedial action. Here is mine at the current time:
You can see that no swap is being used and that memory pressure is green. This is a good sign, but if you notice that you are using significant swap (say more than about 25% of your physical RAM), you may be starting to tax your system. That said, it is the actual amount of reading and writing to swap that causes the slowdown because the OS is having to moving active chunks of application memory onto much slower SSD to make space in RAM. These are "page ins" and "page outs", which you used to be able to see in the Activity Monitor memory overview, but now require other tools (vm_stat or third party tools).
I use iStatMenus, which gives me this overview:
Again, swap memory is showing as zero, but also I have no reads and writes to swap. Even if I had multiple GB of swap memory, it would be the page ins/outs that kill performance. If you close a lot of apps/documents, you will free memory, but if these were already in swap, you won't suddenly see your free RAM increase, although over time, swap usage will decrease.
Other metrics to look out for are: wired, application, compressed, cached, and free memory. Broadly speaking "wired" memory is for OS code that has to stay in memory, application is for apps, compressed is for "infrequently used" parts of application code that can be made smaller until needed, but still stay in memory, cached keep recently used application code and data in memory in case it is need again in the short term, and free memory is memory with no assigned data.
There is a common misunderstanding that having lots of "free" memory is a good thing, like having a healthy bank balance; this is not so. Any free memory should be used for some benefit to the system, generally for caching files and code, so that it can be very quickly referenced (e.g. when you switch applications or documents). Free memory is wasted memory!
You will generally see the memory pressure turn yellow when you start to increase compressed memory to close to about half of your physical RAM (e.g. around 15GB on my 32GB system), or when swap is close to a third of your RAM (c. 10GB in my case), or a combination of both. In my experience high amounts of compressed memory can cause memory pressure warnings, even if swap usage is not particularly high.
TLDR; keep a watch on your memory usage if you are the kind of user who opens lots of apps/documents/brower tabs and doesn't bother to close them, and have a "tidy up" every day or so to prevent getting into a memory starved situtation. I probably have 100 Safari browser tabs open at the moment so it's time I cleared my "virtual desktop"! (Safari doesn't have a "tab sleep" function like Chrome & Edge to reduce memory impact)