Thanks to everyone who keeps posting. Just to clarify, the problem hasn't disappeared in the past few months since I posted in the thread. I just started permanently closing all applications throughout the day as soon as I don't need them, generally keeping Safari tabs to 4-5 max, rebooting once or twice a day... it's like being back in the 1990's.
As for what BobHarris posted: from what can I tell most of the times it's Safari that creates 10-15 different processes, each gradually using gigabytes of virtual memory. Doesn't really matter if you don't have anything on your hard drive, it will eventually eat up all the space, I've already cleared my Mac of everything else than text documents but it's never enough. Since Safari is an Apple-created app and I'm dealing with the hard-drive that I bought my Macbook with I really don't see what I could do to fix the problem other than keep rebooting constantly. Usually before the "Your system has run out of application memory" message appears you'll see like 15 processes named like this upon typing the "ps ax" command in Terminal.
136464540 27290 /System/Library/Frameworks/WebKit.framework/Versions/A/XPCServices/com.apple.WebKit.WebContent.xpc/Contents/MacOS/com.apple.WebKit.WebContent
As far as I remember the problem started with the new version of macOS and Safari.
macOS Monterey, Version 12.2.1, Safari Version 15.3 (17612.4.9.1.8)
I'd be so grateful if anyone found a solution. Sorry to keep bugging you all!