I think such a scenario may be developer error. We can't reliably detect when a component is or is not part of the component hierarchy: a component can tell when it has been added or removed, but not when an ancestor has been added or removed.

On the other hand, an application developer knows when a component is added or removed and can decouple the component from the data.

Swing might have the same issue - how is it handled there?

On Mar 13, 2009, at 5:41 PM, Todd Volkert wrote:

Scenario:

1) 'treeView' is created with 'treeData' and added to the component hierarchy.
2) 'treeView' adds itself as a ListListener  on 'treeData', causing
'treeData' to maintain a reference to 'treeView'
3) 'treeView' is removed from the component hierarchy, but the user
still needs a reference to 'treeData'.

Result: 'treeView' never falls out of scope, and the user has no way
to release the reference to it since it used a private handler as its
event listener.

Should such components only listen for data events while they're
attached to the component hierarchy?

-T

Reply via email to