Avoid out of bounds access if removing a listener while iterating the array.