Over the last few years my 2010 iMac has been suffering with crashes, which always seem to be when using Safari. macOS is always up to date, and this has happened on both Sierra and El Capitan (possibly back to Yosemite too). I have done a fresh install of Sierra, which has not fixed the problem. I have reduced the number of tabs open, last time it happened I only had 4 tabs open. I usually have 2GB out of 8GB RAM free.
When it freezes I can still move the mouse around the screen, the pointer stays in whichever shape it was previously, and does not change over links etc. I cannot select anything. The CAPS lock light illuminates, but I cannot use keyboard shortcuts to change applications etc. I have noticed that Time Machine backups still happen whilst in this state, and the display switches off after 10 minutes as expected - I can then wake the iMac up from the keyboard, but it is still frozen.
Any suggestions on what could be causing this, or how I could fix it?