You can try to implement the desired functions using events. Each managed object generates an event for destruction, and the object manager subscribes to this event so that it can remove the reference to the object from the SplObjectStorage object.
source share