Improved OOME handling

fixes #224

Although this is a big improvement, taking a heap dump is not perfect because it could be that the drive is not big enough. See #264