v.20.8Bug Fix

Fix "Memory limit exceeded" error in extractAllGroups function

Fix the issue when some invocations of extractAllGroups function may trigger "Memory limit exceeded" error. This fixes #13383. #14889 (alexey-milovidov).