You are here: Tuning > Performance Hints > Defragment

Defragment

.NET: Defragment.Defrag("sample.db4o")

Advantage

It is recommended to run Defragment frequently to reduce the database file size and to remove unused fields and freespace slots.

Effect

db4o does not discard fields from the database file that are no longer being used. Within the database file quite a lot of space is used for transactional processing. Objects are always written to a new slot when they are modified. Deleted objects continue to occupy 8 bytes until the next Defragment run. Defragment cleans all this up by writing all objects to a completely new database file. The resulting file will be smaller and faster.

Alternate Strategies

Instead of deleting objects it can be an option to mark objects as deleted with a "deleted" boolean field and to clean them out (by not copying them to the new database file) during the Defragment run. Two advantages:

  1. Deleted objects can be restored.
  2. In case there are multiple references to a deleted object, none of them would point to null.