In some cases using ForLoop can led to OOM when we deal with many elements because we start to create lists with huge capacity.
In this PR we introduce MAX_SLICES limit. Additional improvement is to relax the heap usage by not copying elements to new ArrayLists rather reusing the one in ForLoop which has Iterator<?> it inside.
In some cases using ForLoop can led to OOM when we deal with many elements because we start to create lists with huge capacity.
In this PR we introduce MAX_SLICES limit. Additional improvement is to relax the heap usage by not copying elements to new
ArrayLists
rather reusing the one inForLoop
which hasIterator<?>
it inside.