Skip navigation.
 
mlRe: Core Data troubles - not removing objects
FROM : Chris Hanson
DATE : Fri Nov 02 03:04:31 2007

On Nov 1, 2007, at 3:53 PM, Benjámin Salánki wrote:

>> The sqlite database file format won't grow and shrink in response 
>> to every change you make, for performance reasons data is mapped to 
>> pages which may contain many individual data records (or a single 
>> data record can span many pages).

>
> So are you saying removing an item from the store won't reduce its 
> size on the disk? How can I tell my users that even if they do 
> remove all their data they won't regain any of their precious hard 
> disk space? Surely there has to be a way to reduce the size of the 
> file if I remove data from it. PLease tell me it's possible.


You asked about removing *an* item.  If enough items are removed to 
free up a page in the database file, SQLite's automatic database 
vacuuming will reduce the size of the file as it rearranges the data 
to remove that page.  Similarly, the file size may be reduced if you 
remove an item that itself occupies multiple pages (such as a 
thumbnail image).

An SQLite file is arranged as a collection of pages and the data 
within those pages is managed via B-trees, not as simple fixed-length 
records (which is what it sounds like you're expecting).  This is much 
more efficient for searching and for overall storage, since it allows 
SQLite to optimize how it stores both data and indexes in a single 
file, and is also the foundation of its data integrity (transaction & 
journaling) mechanism.

However, the cost of this is that some delete operations may leave 
holes in the file.  If you delete some data and add other data, the 
holes left by the deleted data may be filled by the added data, or the 
file may be vacuumed to compact its data, whichever SQLite considers 
most appropriate based on the operations you're performing.

Does that make sense?

  -- Chris

Related mailsAuthorDate
mlCore Data troubles - not removing objects Benjámin Salánki Nov 1, 10:04
mlRe: Core Data troubles - not removing objects Adam Swift Nov 1, 23:40
mlRe: Core Data troubles - not removing objects Benjámin Salánki Nov 1, 23:53
mlRe: Core Data troubles - not removing objects Chris Hanson Nov 2, 03:04
mlRe: Core Data troubles - not removing objects Benjámin Salánki Nov 3, 21:09
mlRe: Core Data troubles - not removing objects Ben Trumbull Nov 3, 23:58
mlRe: Core Data troubles - not removing objects Benjámin Salánki Nov 4, 17:37
mlRe: Core Data troubles - not removing objects Bill Bumgarner Nov 4, 17:59