CDI Application and Dependent scopes can conspire to impact garbage collection?

半腔热情 提交于 2019-11-29 01:24:41

Your understanding is correct. This was an oversight in the spec, and something that will be fixed in CDI 1.1. Instance can have a memory leak just like you've described when used in a long running scope such as SessionScoped or ApplicationScoped. What you will need to do is get a hold of the Contextual or Bean for the instance and destroy it that way.

For what you're doing, and to avoid the memory leak you're best off to use the BeanManager methods to create instances (that way you'll also have a handle on the Bean and can destroy it) instead of Instance.

While looking into implementing Jason's suggested workaround, I found some more resources relating to the issue:

The issue: https://issues.jboss.org/browse/CDI-139 and https://issues.jboss.org/browse/WELD-920

Example beanManager operations: https://issues.jboss.org/browse/CDI-14?focusedCommentId=12601344&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-12601344

or org.jboss.seam.faces.util.BeanManagerUtils

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!