The closures in ServiceContainer::$serviceInstantiators are circular
references which prevent destruction of the object. So, delete these
when destroy() is called. Also delete the service instances for good
measure.
Change-Id: Ic8487cb533a09a8fcc69eba4f5d1bbb71558ae08
}
}
+ // Break circular references due to the $this reference in closures, by
+ // erasing the instantiator array. This allows the ServiceContainer to
+ // be deleted when it goes out of scope.
+ $this->serviceInstantiators = [];
+ // Also remove the services themselves, to avoid confusion.
+ $this->services = [];
$this->destroyed = true;
}