Fixed issue #1926 and #2164
Added dump of heap in case of OOM