Currently all target objects are added to the targetSet, this looks to be done so when the application is shutdown destroy can be called on each target object. But if the target is not a DisposableBean, then there is nothing to destroy and the object reference is being held on to for no good reason. On app servers that turn over threads often (jboss/undertow) this can lead to a memory leak. Since the thread/threadlocal is gone but the targetSet has still has it's reference for destroying, but there is nothing to destroy.
Comment From: pivotal-cla
@slandrum00 Please sign the Contributor License Agreement!
Click here to manually synchronize the status of this Pull Request.
See the FAQ for frequently asked questions.
Comment From: pivotal-cla
@slandrum00 Thank you for signing the Contributor License Agreement!
Comment From: sbrannen
Hi @slandrum00,
Thanks for submitting your first pull request ever!
But if the target is not a DisposableBean, then there is nothing to destroy and the object reference is being held on to for no good reason.
That's unfortunately not true. The DisposableBean
interface is only one of the mechanisms supported for destroying those target beans. The full list of supported mechanisms is documented in the class-level Javadoc for org.springframework.beans.factory.support.DisposableBeanAdapter
:
Adapter that implements the
DisposableBean
andRunnable
interfaces performing various destruction steps on a given bean instance:
- DestructionAwareBeanPostProcessors;
- the bean implementing DisposableBean itself;
- a custom destroy method specified on the bean definition.
Thus, limiting the support to only DisposableBean
would be a breaking change.
In light of that, I am closing this PR.