Careful with that! Your array will grow on every loop iteration, and every iteration will force a copy of the entire array (to a location with enough space for one additional element). The larger array, the longer it will take to make that copy, so the code will steadily slow down while at the same time consuming more memory. It would be a very good idea to limit the array size to the number of elements you actually need.