allocate edge flip results only once and free all memory at the end