Description
currently, shutting down the kernel (between tests generally) is doing several steps:
- running the shutdown logic of each bundle
- removing the container reference from each bundle
- removing the container reference from the kernel
At this point, we consider that the container is meant to be out of scope.
However, as soon as a service is aware of the container, we get a cyclic object graph because of the service reference hold by the container. This means that none of the services will be garbage collected by the refcount.
I suggest adding a clear()
method on the container (and a ClearableContainerInterface
used by the kernel to know whether it can clear the container) which would clear the list of service instances ($this->services
, $this->scopedServices
and $this->scopeStacks
). this would remove the reference hold by the container itself, meaning that most services will then be able to be collected by the refcount (cyclic references inside the service object graph should be rare, given the only way to achieve them is to add a reference at runtime. the container prevents having cyclic service references). And the container itself will then be collected once all container aware services are.
what do you think about that @fabpot and @nicolas-grekas ?