Sets a threshold in ArrayCollection where array is recreated if surpassed

this to avoid big arrays with all its references still set. This is an
artofact of the very purpose of ArrayCollection, that clear() should be
as performant as possible.
Fix broken test
Merge pull request #3655 from tinwelint/2.2-avoid-big-reference-array-arr-coll

Sets a threshold in ArrayCollection where array is recreated if surpassed
Make sure that when checking the decrement of the counter the thread
is still holding the lock by non-returning from the create method.
Otherwise a race might happen, i.e., before the condition has been
verified the other thread would be scheduled and access the create
method (since the other thread has released the lock) and it will
increment again the counter causing the test to fail.