Deleting Data
Deleting data does not require performing explicit deleting actions like DELETE FROM table WHERE…. Instead you just need to clear any references to the object in your object-graph and store those changes.
If a stored object is not reachable anymore its data will be deleted from the storage later.
This behavior is comparable to Java’s garbage collector.
Basic Deletion
Remove the reference to the object and store the parent:
root.getMyArrayList().remove(0);
storage.store(root.getMyArrayList());
Deleting from Different Collection Types
Removing from a List
// Remove by index
root.getOrders().remove(0);
storage.store(root.getOrders());
// Remove by reference
root.getOrders().remove(order);
storage.store(root.getOrders());
// Remove with condition
root.getOrders().removeIf(o -> o.isCancelled());
storage.store(root.getOrders());
Bulk Deletion
When removing many objects, batch the removals and store once:
// Remove all inactive customers
List<Customer> inactive = root.getCustomers().stream()
.filter(Customer::isInactive)
.toList();
root.getCustomers().removeAll(inactive);
storage.store(root.getCustomers());
Important: Always Store the Parent
|
You must store the parent object that contains the reference, not the deleted object itself. Incorrect (does nothing for deletion):
Correct:
|
When Is Data Actually Erased?
| Deleted data is not erased immediately from the storage files. |
The erasing from the storage files is done by the housekeeping process. Housekeeping runs in the background and reclaims space from deleted (unreachable) objects during its garbage collection phase.
The timing depends on your housekeeping configuration:
-
Housekeeping interval — how often housekeeping runs
-
Time budget — how much time each housekeeping cycle is allowed to spend
Until housekeeping reclaims the space, the data remains in the storage files but is no longer accessible through the object graph.
Deleting with Lazy References
If the object to delete is behind a Lazy reference, you need to clear the lazy reference and store the parent.
Clearing a Lazy Field
public class DataRoot
{
private Lazy<List<Order>> archive = Lazy.Reference(new ArrayList<>());
public Lazy<List<Order>> getArchive()
{
return this.archive;
}
public void setArchive(Lazy<List<Order>> archive)
{
this.archive = archive;
}
}
// Delete the archived data
Lazy.clear(root.getArchive()); (1)
root.setArchive(null); (2)
storage.store(root); (3)
| 1 | Clear the lazy reference to free the loaded data from memory. The static Lazy.clear() is null-safe — unlike calling .clear() on the instance directly, it does not throw a NullPointerException if the reference is null. |
| 2 | Set the field to null to remove the reference from the object graph |
| 3 | Store the parent so the change is persisted |