In a world where manual memory allocation and pointers still rule (Borland Delphi) I need a general solution for what I think is a general problem:
At a given moment an object can be referenced from multiple places (lists, other objects, …). Is there a good way to keep track of all these references so that I can update them when the object is destroyed?
If you want to notify others of changes you should implement the ‘Observer Pattern’. Delphi has already done that for you for TComponent descendants. You can call the TComponent.FreeNotification method and have your object be notified when the other component gets destroyed. It does that by calling the Notification method. You can remove yourself from the notification list by calling TComponent.RemoveFreeNotification. Also see this page.
Most Garbage Collectors do not let you get a list of references, so they won’t help in this case. Delphi can do reference counting if you would use interfaces, but then again you need to keep track of the references yourself.