<font size=2 face="sans-serif">Thank you Martin for the useful summary!</font>
<br>
<br><font size=2 face="sans-serif">+1: only support the Instance.destroy()
to destroy the depended scoped objects created by the same Instance object.
</font>
<br>
<br><font size=2 face="sans-serif">Many thanks,<br>
Emily<br>
===========================<br>
Emily Jiang<br>
WebSphere Application Server, CDI Development Lead</font>
<br><font size=2 face="sans-serif">&nbsp;<br>
MP 211, DE3A20, Winchester, Hampshire, England, SO21 2JN<br>
Phone: &nbsp;+44 (0)1962 816278 &nbsp;Internal: 246278<br>
<br>
Email: emijiang@uk.ibm.com <br>
Lotus Notes: Emily Jiang/UK/IBM@IBMGB<br>
</font>
<br>
<br>
<br>
<br><font size=1 color=#5f5f5f face="sans-serif">From: &nbsp; &nbsp; &nbsp;
&nbsp;</font><font size=1 face="sans-serif">Martin Kouba &lt;mkouba@redhat.com&gt;</font>
<br><font size=1 color=#5f5f5f face="sans-serif">To: &nbsp; &nbsp; &nbsp;
&nbsp;</font><font size=1 face="sans-serif">cdi-dev &lt;cdi-dev@lists.jboss.org&gt;,
</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Date: &nbsp; &nbsp; &nbsp;
&nbsp;</font><font size=1 face="sans-serif">18/05/2016 08:55</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Subject: &nbsp; &nbsp;
&nbsp; &nbsp;</font><font size=1 face="sans-serif">[cdi-dev] CDI-519
notes</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Sent by: &nbsp; &nbsp;
&nbsp; &nbsp;</font><font size=1 face="sans-serif">cdi-dev-bounces@lists.jboss.org</font>
<br>
<hr noshade>
<br>
<br>
<br><tt><font size=2>Hi all,<br>
<br>
John is questioning the clarification introduced in CDI-519. I think <br>
it's correct although not quite intuitive.<br>
<br>
Below are some notes we should consider (I know it's long but the topic
<br>
is quite complicated):<br>
<br>
CreationalContext<br>
=================<br>
<br>
Besides other things, holds the references to all depenent bean <br>
instances together with their CCs (for normal scopes this is the <br>
responsibility of the context). So that these could be correctly <br>
destroyed when CC.release() is called.<br>
<br>
Note that the context must pass the same instance of CC to <br>
Contextual.destroy() that it passed to Contextual.create() when it <br>
created the instance.<br>
<br>
Possible &quot;leak&quot; description<br>
===========================<br>
The problem is if an Instance is injected into a normal scoped bean Foo
<br>
and is used to get other @Dependent bean instances via Instance.get().
<br>
Each of this call returns a new depenent bean instance bound to the <br>
lifecycle of the Instance, which is also depenent and so it's <br>
effectively bound to the lifecycle of Foo. And that was the original <br>
motivation to introduce Instance.destroy().<br>
<br>
Instance.select()<br>
=================<br>
The spec states the select() method returns a child Instance. What is <br>
that &quot;child&quot; is not defined though. In Weld, a child Instance
shares the <br>
CreationalContext of the parent Instance. And I think this makes sense.<br>
<br>
CDI-519 summary<br>
===============<br>
Instance.destroy() cannot be used for dependent bean instances not <br>
created by the same Instance object.<br>
<br>
The reason: a dependent bean instance does not know the object it <br>
depends on. So if we pass a dependent bean instance it must be &quot;managed&quot;
<br>
by the CC of the Instance. Otherwise, we would not be able to destroy <br>
the bean instance and all its dependent dependencies correctly.<br>
<br>
 From the spec point of view it's clear:<br>
&quot;An instance of a bean with scope @Dependent obtained by direct <br>
invocation of an Instance is a dependent object of the instance of <br>
Instance.&quot; A dependent bean instance is bound to the lifecycle of
<br>
Instance (or one of its child) so the Instance should be responsible for
<br>
destroying it. Done.<br>
<br>
 From the user point of view: I don't think it's a big problem. BTW it
<br>
does not work in any CDI 1.1+ version of Weld. I'm not sure about OWB.<br>
<br>
Impl notes<br>
==========<br>
If we allow this then we would probably have to create some central <br>
registry of CCs and during Instance.destroy() iterate over all these CCs
<br>
and try to destroy given depenent bean instance. This will be <br>
complicated, error-prone and inefficient.<br>
<br>
Thanks,<br>
<br>
-- <br>
Martin Kouba<br>
Software Engineer<br>
Red Hat, Czech Republic<br>
_______________________________________________<br>
cdi-dev mailing list<br>
cdi-dev@lists.jboss.org<br>
</font></tt><a href="https://lists.jboss.org/mailman/listinfo/cdi-dev"><tt><font size=2>https://lists.jboss.org/mailman/listinfo/cdi-dev</font></tt></a><tt><font size=2><br>
<br>
Note that for all code provided on this list, the provider licenses the
code under the Apache License, Version 2 (</font></tt><a href="http://www.apache.org/licenses/LICENSE-2.0.html"><tt><font size=2>http://www.apache.org/licenses/LICENSE-2.0.html</font></tt></a><tt><font size=2>).
For all other ideas provided on this list, the provider waives all patent
and other intellectual property rights inherent in such information.<br>
<br>
</font></tt>
<br><font size=2 face="sans-serif"><br>
Unless stated otherwise above:<br>
IBM United Kingdom Limited - Registered in England and Wales with number
741598. <br>
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6
3AU<br>
</font>