It closes because the object gets destroyed at the end of the function.