Physics2D.OverlapCircleAll + OnTriggerExit2d

Hi there, I have following method of detecting nearby gameobjects

Collider2D colliders = Physics2D.OverlapCircleAll (points.position,0.2f);

         for(int i=0;i<colliders.Length;i++){

             if (colliders *.gameObject.GetComponent<Foo>() != null) {*

colliders .gameObject.GetComponent().Bar = true
}
So I set bool Bar value to true if the gameobject is in Physicss2d circle.
When the gameobject leaves the circle I need to set Bar variable to false.
Is there a way to achieve this without creating dynamic List of gameobjects?

To save yourself constantly regenerating a List<>, I would use OnTriggerEnter2D and OnTriggerExit2D along with a CircleCollider2D trigger to add and remove objects from the list, respectively.

 void OnTriggerEnter2D (Collider2D collider) {
    if (collider.gameObject.getComponent() != null) {
        objectList.Add (collider.gameObject);
        collider.gameObject.GetComponent ().Bar = true;
}
void OnTriggerExit (Collider2D collider) {
    if (collider.gameObject.getComponent() != null) {
        objectList.Remove(collider.gameObject);
        collider.gameObject.GetComponent ().Bar = false;
}

Sorry for untested code. It’ll probably need some tweaking.