We can't iterate through the pages like that as the array mutates as we delete pages. Use clear instead.
mentioned in commit 3af2cfcb