Overwrite realm file


Wondering if anybody can provide information for the following use case…

My Xamarin app has the ability to transfer (backup/restore) a realm from 1 device to another via iCloud and the entire workflow is working except for the restore phase.

The restore is a simple download from iCloud, unzip file and copy realm file over the current realm which appears to work without exceptions been thrown. The issue is - the app still thinks the original realm is current so nothing from the restored realm file is showing. I have to terminate the app and run it again for the new content to show.

Ideas suggestions greatly appreciated as the user experience isn’t great if they have to restart the app.



I think the following will work:

  1. download from iCloud
  2. unzip
  3. open both realm files
  4. remove all data from the new realm
  5. copy all data from backup to new realm
  6. delete backup realm


If you’re just overwriting a file, you need to close all Realm instances that were reading that file. Are you sure you’ve done that prior to the restore?


Thanks nirinchev,

I’m using MVVM light to manage view models that have realm references, disposing of these objects isn’t quite straight forward so have a method in a base class that does

realm = null;

Its brute force but does the job as there doesn’t appear to be any Close() method in the Xamarin implementation.

I also create new realm instances in background threads and would expect these instances to be destroyed once the thread has completed… maybe not??


Cheers freeubi,

Nasty and… maybe plan B - thanks


If using Realms on background threads it’s very important to dispose of them. If you already do that, it’s quite surprising that overwriting the Realm file doesn’t work.