Deleting an object is as simple as storing an object. You simply call the delete-method on the container to delete it. By default only the object you pass to the delete method is deleted. All referenced objects are not deleted.
Car car = FindCar(container); container.Delete(car); // We've deleted the only care there is AssertEquals(0, AllCars(container).Count); // The pilots are still there AssertEquals(1, AllPilots(container).Count);
Dim car As Car = FindCar(container) container.Delete(car) ' We've deleted the only care there is AssertEquals(0, AllCars(container).Count) ' The pilots are still there AssertEquals(1, AllPilots(container).Count)
What happens when you delete a object which is still referenced by other objects? Well in such cases that reference is set to null.
Pilot pilot = FindPilot(container); container.Delete(pilot);
Dim pilot As Pilot = FindPilot(container) container.Delete(pilot)
// Now the car's reference to the car is set to null Car car = FindCar(container); AssertEquals(null, car.Pilot);
' Now the car's reference to the car is set to null Dim car As Car = FindCar(container) AssertEquals(Nothing, car.Pilot)
Often you want to ensure that a object isn't referenced anymore, before you can delete it. However such referential integrity isn't supported at the moment. You need to implement your integrity checks manually, for example with callbacks.
Additionally you can configure cascading behavior for deletion. See "Cascading Deletion"
Also collections are treated like regular objects and need to be deleted explicitly. See "Collections And Arrays"