You're hitting the infamous "Out of Memory" (OOM) bug. This has gone for more than 16 years, and it's only since mid-2019 that this bug is getting attention... without any reliable fix since.
This is due to Linux bad habit to cache things, overcommitting way too much RAM and unability to tell how much unreclaimable cache/buffers you really have.
However, there's something simple that works really well to prevent you hitting that OOM bug: nohang.
You'll find out why you're hitting OOM there, but also a ppa down that link to install it.
This will not fix the bug, but this is the best thing we have against that nowadays.
Do also consider using a less RAM hogging Desktop Environment, since every software you do launch with a heavy one will use even more RAM. Also, Gnome 3, despite being able to do far less than Mate (a GTK 3-based Gnome 2 revival), is the hoggiest one after Cinnamon, comes then KDE and Mate.
I would suggest XFCE, which only eats around 600MB of RAM instead of the more than 1.3GBs of KDE (old Gnome 3 from 7 years ago already ate that much, should be more nowadays).
Same goes for browsers, anything Chrome/Chromium-based hogs a lot (except... Edge on Windows). Avoid Electron or JavaScript-based "apps" as much as you can, since they're eating way too much RAM for what they can do, or anything that uses a lot of RAM for little functionnality (e.g. a fully-featured text editor shouldn't use more than 30MB of RAM, etc ).
What duthils said is good (ZRAM and CGroups), but sometimes buying more RAM to cater bad developers who don't want to optimize their software isn't an appropriate fix.
Also consider, tab suspenders for your browsers, like Firefox's "Auto Tab Discard" extension and Vivaldi, which is a very powerful browser based on Chromium that natively have manual tab discarding if you really need such Chromium-based browser.
Since you're a developper: Remember, unused RAM IS NOT wasted RAM (the reverse wrong assumption is almost always made by... web developpers).
This is especially true when cached RAM is mostly not real reclaimable RAM, which is exactly why you're hitting that OOM issue.
You can easily check that by looking at top
's "available" RAM after an echo 3 > /proc/sys/vm/drop_caches
to see that there's still some cache left, often by a lot.