菜鸟教程小白 发表于 2022-12-12 23:57:46

objective-c - 核心数据 sqlite 文件增长


                                            <p><p>我有一个同步过程,我使用 <code>Core Data</code> 来存储大量信息。有几次我用管理器下载了真正的 <code>SQLite</code> 数据库文件来检查数据是否正确。 </p>

<p>几天前,我发现两个 <code>SQLite</code> 文件的大小差异很大。一个文件是 80MB,另一个文件是 100MB。当我使用 <code>SQLite</code> 查看器检查其中的数据时,没有任何区别。相同的表,相同的索引,相同的行。这个怎么可能?当我通过 <code>Core Data</code> 删除对象时,文件中是否仍有一些数据?</p>

<p>编辑:</p>

<p>解决方案是一个选项标志,可以插入一个选项 NSDictionary 并作为参数添加到 addPersistentStore 方法。</p>

<pre><code>NSSQLiteManualVacuumOption
Option key to rebuild the store file, forcing a database wide defragmentation when the store is added to the coordinator.

This invokes SQLite&#39;s VACUUM command. It is ignored by stores other than the SQLite store.
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>出于性能原因,Sqlite 在删除数据时不会主动返回未使用的磁盘空间。这可能就是您看到差异的原因。有关详细信息,请参阅此链接:</p>

<p> <a href="http://www.sqlite.org/faq.html#q12" rel="noreferrer noopener nofollow">SQLite FAQ</a> </p></p>
                                   
                                                <p style="font-size: 20px;">关于objective-c - 核心数据 sqlite 文件增长,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/13875255/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/13875255/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: objective-c - 核心数据 sqlite 文件增长