You are here: Advanced Features > Defragment > Tracking Defragmentation Errors

Tracking Defragmentation Errors

You can pass a defragmentation listener to the defragmentation process. This listener will be notified when there's no object for an id in the database. This means that a object has a reference to a non-existing object. This happens when you delete objects which are still referenced by other objects.

private class DefragmentListener : IDefragmentListener
{
    public void NotifyDefragmentInfo(DefragmentInfo defragmentInfo)
    {
        Console.WriteLine(defragmentInfo);
    }
}
DefragmentationExample.cs: Defragmentation listener implementation
Private Class DefragmentListener
    Implements IDefragmentListener
    Public Sub NotifyDefragmentInfo(ByVal defragmentInfo As DefragmentInfo) _
        Implements IDefragmentListener.NotifyDefragmentInfo

        Console.WriteLine(defragmentInfo)
    End Sub
End Class
DefragmentationExample.vb: Defragmentation listener implementation
DefragmentConfig config = new DefragmentConfig("database.db4o");
Defragment.Defrag(config, new DefragmentListener());
DefragmentationExample.cs: Use a defragmentation listener
Dim config As New DefragmentConfig("database.db4o")
Defragment.Defrag(config, New DefragmentListener())
DefragmentationExample.vb: Use a defragmentation listener