Once fully frozen, it's not really able to be saved.
Is it a full freeze? Press CAPS-LOCK or NUM-LOCK to see if the hardware is still responding.
If it is, it might just be a DE freeze. Try to SSH into into your frozen device, from another PC or phone.
Or press CTRL-ALT-F7 to see if you can switch to a terminal and login.
Once in, use ps -ef, or top to see and kill what might be causing a freeze.
Turn on auto-save in LibreOffice(you usually only lose a sentence or 3 words with this on).
Investigate IDEs with auto-backup or an autosaved change-history.
--//--
To diagnose whether you have bad RAM, boot from a LiveUSB distro and use it for a day or week.
If no freezes, reinstall a fresh OS.
If it still freezes, get new RAM, or replace whole PC/laptop.