Fixes in case of OOM
Merge pull request #1781 from hardening/collections_fixes

Fixes in case of OOM