Unref mainloop when finished.