1

We have recently planned to switch from SQLite to Realm in macOS and iOS app due to db file corruption issue with SQLite so we first started with macOS app. All coding changes were smooth and app started working fine.

Background about app and DB usage - app really uses DB very heavily and performs too many read and writes to DB in each minute and saves big xml's to it. In each minute it writes / updates around 10-12 records (at max) with xml and reads 25-30records too. After each read it deletes data along with xml from database and my expectation is once data is deleted it should free up space and reduce file size but looks like it is growing continuously.

To test the new DB changes we kept app running app 3-4 days and DB file size went to 64.42GB and app started being slow. Please refer the attached screen shot. enter image description here

To further debug, I started app with new DB file and size was 4KB but within 5min it goes to 295KB and never reduced in size even records were continuously added and deleted.

To further clarify, app uses NSThreads to perform various operations and those threads writes and reads data to DB but with proper begin\commit transactions. I also read at 'Large File Size' at https://realm.io/docs/java/latest/#faq and tried to find compactRealm but can't find it in objective c.

Can anybody please advise.

Update - I Give up on Realm

After 15days of efforts, Finally I have stopped usage of Realm and starting to fix/workaround db file corruption issue with SQLite. Realm Huge DB file issue was fixed by making changes to code for threads but then I started getting Too many open files error after running the app for 7-8 hours.

Debugged for whole week and made all possible changes and at some point looks like all was good as xcode were not showing any open files. But again I started getting Too many open files crash and then debugged with instrument and found there were so many open files to realm database, lock, commit and cv files.

I am sure there are no leaks in app and xcode also does not shows those open files in Disk usage as well. I decided to invoke lsof command in code before and after Realm calls and most of the it doesn't increase open file count but sometime n between it increases. In My app it started from 120 files to 550 in around 6 hours. Xcode looks all fine via Disk usage but instrument shows open files.

No good support from Realm team, sent email to them, just got one response. Made many changes to code following their suggestions and doesn't work at all so gave up on it. I think it's good for small apps only.

M P
  • 352
  • 3
  • 14
  • The database is growing because of a large amount of data not written yet. The database is saving references to older versions of the data. This is explained and there's a few advices on this topic on the Realm docs for "File size & tracking of intermediate versions": https://realm.io/docs/objc/latest/#file-size--tracking-of-intermediate-versions – Orlando Jan 30 '17 at 06:31
  • I already read all these but can't really find any way to track actual cause of issue. My understanding is also that upon app restart it should automatically free up any unused space and revert the DB to actual size. How can i track where exactly the issue is? Also it mention that `To avoid this issue you, may call invalidate to tell Realm that you no longer need any of the objects that you've read from the Realm so far, which frees us from tracking intermediate versions of those objects. The Realm will update to the latest version the next time it is accessed.` so where to call invalidate? – M P Jan 30 '17 at 09:02
  • I understand. It's not easy for anyone to track the issues. I've tried myself in the past with no total success. The method you invoke is `-invalidate` on the RLMRealm class. https://realm.io/docs/objc/latest/api/Classes/RLMRealm.html#/c:objc(cs)RLMRealm(im)invalidate – Orlando Jan 30 '17 at 19:26
  • There's not sufficient information in your question here to determine what's resulting in the behavior you're seeing. I'd suggest reaching out via email to help@realm.io or [filing a GitHub issue](https://github.com/realm/realm-cocoa/issues/new) so that people at Realm can help you directly with this in a format that's more conducive to back and forth discussion. – bdash Jan 31 '17 at 00:15
  • Thanks for suggestion, i am going to send email to them now. – M P Jan 31 '17 at 01:17
  • Gave up on realm!!! No good support as they mention over their website. – M P Feb 07 '17 at 04:37
  • 1
    Hi Mahesh, JP from Realm here. I'm sorry to see that Realm caused so much trouble for you. Our records show that two of our engineers contacted you within 24 hours of this being posted and attempted to get more information from you to help optimize your usage of Realm to avoid holding on to old Realm versions (which keeps data from that point in time alive). We emailed you again a few days later encouraging you to update to 2.4.2 and report back with more information. We have yet to hear back from you. I've followed up on that email thread in case you'd still like to resolve this. – jpsim Feb 13 '17 at 23:06
  • Hello JP, Sorry was pulled way, Just replied over email. Thanks for following up. – M P Feb 14 '17 at 04:43
  • We are also facing this error. How did you solve this issue? ..any pointer will be really really helpful. Thanks – Tushar May 19 '17 at 17:32
  • @Tushar I improved my SQLite classes instead of investing more time in Realm, worked with realm support team later on too for many days but nothing worked though it was improved and wasn't always happening but it was still causing file size issue now and then. – M P May 20 '17 at 13:37
  • @MP, Thanks for your reply. Good to know that. – Tushar May 22 '17 at 17:03
  • https://stackoverflow.com/questions/34084108/do-we-have-to-use-explicit-autorelease-pool-when-using-realm-in-gcd-even-under-a/51047849#51047849 – YanQing Jun 27 '18 at 02:35

0 Answers0