拥有庞大数据的领域 [英] Realm with huge data

查看:61
本文介绍了拥有庞大数据的领域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用realm's数据库时遇到问题,一切正常,但问题在于数据的大小,每次使用我的应用程序时,我发现除300 Mo以外,还关闭了所有领域实例,我很清楚首先确保表为空,但每次运行应用程序时,数据库的大小始终会变大.

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.

我使用version 0.80是因为我使用了一些自定义方法.

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

推荐答案

领域称为MVCC 多版本并发控制数据库.这意味着您的数据的多个一致版本可以同时存在.但是,这有一些含义:

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)只要您拥有两个版本的Realm数据,Realm将必须维护这两个版本之间的差异.差异越大,占用的空间越多.

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)非循环线程不会自动更新,因此,如果在后台线程上打开了Realm实例,则必须手动确保更新该Realm实例.这可以通过调用Realm.refresh()或执行写事务来完成.忘记刷新或关闭后台线程上的领域是文件大小爆炸的最常见原因.

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)diff的大小与您要进行的提交次数有关,因此最好不要执行较大的提交,而要进行较小的提交.

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)目前,Realm不再回收不再使用的空间.假设您的数据库文件已扩展到400 MB,因为您同时拥有两个版本的数据.当您关闭最旧的版本时,即使内部数据可能仅为200 MB,光盘上的文件仍为400 MB.这正在处理中,但是您也可以通过调用

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().

这篇关于拥有庞大数据的领域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆