Realm with huge data

心不动则不痛 提交于 2019-12-11 16:29:27

问题


I had an issue with a realm's database, everything work fine but the problem is the size of data, I found more than 300 Mo every time I use my application, I close all the instance of realm, I clear tables in the beginning to be sure that the database is empty but always the size become bigger every time I run the application.

I use the version 0.80 because I use some custom methods.


回答1:


Realm is what is called a MVCC Multi-version Concurrency Control database. This means that multiple consistent versions of you data are allowed to live at the same time. This however has some implications:

1) As long as you have two versions of Realm data alive, Realm will have to maintain the diff between these versions. The bigger the diff the more space is used.

2) Non-looper threads are not automatically updated, so if you have a Realm instance open on a background thread you must manually make sure to update that Realm instance. This can be done by either calling Realm.refresh() or do a write transaction. Forgetting to refresh or close Realms on background threads are the most common cause for the file size to explode.

3) The size of the diff has a correlation to how many commits you are making, so it is preferable to do fewer larger commits than many small.

4) Right now Realm doesn't reclaim space no longer in use. So let's say that your DB file expanded to 400 MB because you had 2 versions of your data live at the same time. When you then close the oldest version, the file on disc remains at 400 MB even though the internal data might only be 200 MB. This is something that is being worked on, but you can also reclaim the space manually by calling Realm.compactRealm().



来源:https://stackoverflow.com/questions/33090787/realm-with-huge-data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!