The SysRq key can run a bunch of kernel-level commands, eg oom_kill.
oom_kill will kill the process taking up the most memory.
In most cases this should unfreeze Ubuntu.
You can run oom_kill from the keyboard with the following shortcut:
Most laptops don’t have a physical SysRq key. Instead use the keyboard combination fn + s.
Sometimes the SysRq key is only recognised on release.
To run oom_kill on these machines, after enabling it, do the following: