How does OverlapAreaNonAlloc (non) allocation works?

Hi there, I have a question regarding OverlapAreaNonAlloc. I’d like to use it for collision detection. The part I’m not sure I understood is this (quoted from documentation):

“but the results array will not be resized if it doesn’t contain enough elements to report all the results.”

This basically means that if my character can collide with, let’s say, a maximum of 2 ground elements at the same time (think of it as different platforms), then I should allocate a Collider2D for two elements (or more, in other case scenarios) explicitly, before passing the array as a parameter of OverlapAreaNonAlloc?

Thanks.

It’s pretty simple; you allocate the array, it’ll only fill up to the size of the array or the number of results (whichever is lowest).

Don’t allocate an array each time you call it otherwise that’d defeat the purpose right?

Allocate a relatively large one once up to the size of results you’re interested in and reuse it. Doing that means there’s no garbage collection.