Hey,

I have a question about the implementation of @Dependent bean destruction in OpenWebBeans. As per 2.5.4.2. of the cdi spec (https://jakarta.ee/specifications/cdi/4.0/jakarta-cdi-spec-4.0.pdf page 77) "Finally, the container is permitted to destroy any @Dependent scoped contextual instance at any time if the instance is no longer referenced by the application (excluding weak, soft and phantom references).". Is this implemented in OpenWebBeans, and if so is it enabled by default or do I have to configure it?


My motivation for having something like this is the following: In the application I am working on @Dependent beans are pretty widely used (I'm guessing because by using them one didn't have to think about lifetimes/thread safety so much). The developers that did this however usually did not remember to call `instance.destroy(bean)` after they were done using that object. This lead to memory leaks (because the OpenWebBeans Instance kept references to those objects, as it should if I understood the spec correctly) and my application has some pretty horrible workarounds in place to make those memory leaks go away. I would like to get rid of those workarounds, or at least use a less horrible one. The workarounds we have in place are also very old and were originally written for (I believe) OWB 1.x. It may very much be that the current version (which we are using) no longer needs (some of) the workarounds, my goal is to get a better understanding of what should be happening.


Practically what I'm looking for is a way to declare a bean in a way that if I get() it via an instance, that instance will immediately forget about the bean after handing it to me so that the bean can be garbage collected once I'm done using it. If anybody has an idea how to achieve this either with built-in means or with extensions I would appreciate any ideas or further resources.


Best,

Christian

Reply via email to