I want to store Person objects in DB4O. The Person Location field can be changed over time. So I retrieve a person from the DB and call a method to set the location field to a new Location object. (I want the Location objects to be immutable i.e. DDD Value Objects).
This works, however the previously assigned Location objects remain the database. How can I configure DB4O to remove these orphaned Location objects? Or do I need some custom process to garbage collect?
Simplified classes for this example:
class Person {
Location location;
public void Move(Location newLocation) {
location = newLocation;
}
}
class Location {
public Location(string city) {
this.City = city;
//etc
}
public readonly string City;
/// more fields...
}
EDIT: Some more information - Person is meant to be an DDD aggregate root. So there are no external references to a person's internal state. If Person updates its location, then the old location should cease to exist.