Close the Realm instance after a migration

@bmunkholm @cmelchior @kneth