Strange! Are you on the latest beta of macOS? Do you have the whatever the heck it's called search indexing thing that Mac OS has disabled? Those are the only two things that I'm doing with my system that I can think of offhand. I like never have situations where I'm out of RAM and swapping and if I do it's never to the point where it's making my computer unusable. I even use VS code with a whole bunch of really complicated extensions installed for different workspaces and it's no issue.
Edit: are you closing things or are you quitting things?