iOS:Realm文件的大小比GB高出指数级

时间:2021-10-06 01:55:16

I am using Realm as persist store for swift based iOS application.

我使用Realm作为基于swift的iOS应用程序的持久存储。

I have four tables with 6 columns each and each table is having 5k entries each table.(all are strings).This structure is reaching to 3GB.

我有四个表,每个表有6列,每个表每个表有5k个条目。(都是字符串)。这个结构达到3GB。

what could be the issue it reaches 3GB?

什么可能是它达到3GB的问题?

1 个解决方案

#1


0  

First of all, please make sure that the data is actually 3 Gbytes or not. If it contains a lot of transaction version data, the file size will increase from the actual size. To do this, execute compaction or copy the Realm file.

首先,请确保数据实际上是3 GB。如果它包含大量事务版本数据,则文件大小将从实际大小增加。为此,请执行压缩或复制Realm文件。

Please see more details: https://realm.io/docs/swift/latest/#limitations-file-size ​ At that time, if the file size does not change, 3 Gbytes of data is actually stored, so it can not be made smaller. If the file size decreases, the file size is larger than the actual due to the transaction version pinning.

请参阅更多详细信息:https://realm.io/docs/swift/latest/#limitations-file-size那时,如果文件大小没有改变,实际存储了3 GB的数据,所以它不能做得更小如果文件大小减小,则由于事务版本固定,文件大小大于实际大小。

When I look at your code, you are using Realm in multithread, so there is a possibility to occur unintentional version pinning. Try to use autorelease pool to minimize the lifetime of Realm instance. Also, setting shouldComplatOnLaunch to periodically compact at startup can also help solve the problem.

当我查看你的代码时,你在多线程中使用Realm,因此有可能发生无意的版本固定。尝试使用自动释放池来最小化Realm实例的生命周期。此外,设置shouldComplatOnLaunch以在启动时定期压缩也可以帮助解决问题。

#1


0  

First of all, please make sure that the data is actually 3 Gbytes or not. If it contains a lot of transaction version data, the file size will increase from the actual size. To do this, execute compaction or copy the Realm file.

首先,请确保数据实际上是3 GB。如果它包含大量事务版本数据,则文件大小将从实际大小增加。为此,请执行压缩或复制Realm文件。

Please see more details: https://realm.io/docs/swift/latest/#limitations-file-size ​ At that time, if the file size does not change, 3 Gbytes of data is actually stored, so it can not be made smaller. If the file size decreases, the file size is larger than the actual due to the transaction version pinning.

请参阅更多详细信息:https://realm.io/docs/swift/latest/#limitations-file-size那时,如果文件大小没有改变,实际存储了3 GB的数据,所以它不能做得更小如果文件大小减小,则由于事务版本固定,文件大小大于实际大小。

When I look at your code, you are using Realm in multithread, so there is a possibility to occur unintentional version pinning. Try to use autorelease pool to minimize the lifetime of Realm instance. Also, setting shouldComplatOnLaunch to periodically compact at startup can also help solve the problem.

当我查看你的代码时,你在多线程中使用Realm,因此有可能发生无意的版本固定。尝试使用自动释放池来最小化Realm实例的生命周期。此外,设置shouldComplatOnLaunch以在启动时定期压缩也可以帮助解决问题。