>>When layering models like this, you need to be careful with listeners. You
>>should make sure when the model nearest the component has no listeners
[quoted text clipped - 9 lines]
>
> Would there be any problems with this implementation?

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/
>>>When layering models like this, you need to be careful with listeners.
>>>You should make sure when the model nearest the component has no
[quoted text clipped - 17 lines]
> JTree Composite model Underlying model
> ------> ------>
I don't understand what you mean by inner classes. For now I'm assuming
this has something to do with Sun's implementation of listeners that you
know about and I don't, because the way I understand it, the subscriber does
indeed initially need a reference to the observed object to subscribe to it,
but it can then forget about that reference. The observed object, simply
needs a list of references to all items subscribing to it; when no one is
subscribing to it, that list is empty (i.e. it doesn't have references to
any other object).
(I'm also not sure I understand the significance and distinction between
the upper and lower arrows).
> The JTree and composite model are all about a single display. Suppose the
> underlying model is longer lived. Removing the composite model from the
[quoted text clipped - 5 lines]
>
> The composite model (and anything it refers to) is not collectible.
I thought Sun's garbage collection algorithm had something to do with
whether the objects were reachable from live code. Assuming the composite
model and the underlying model don't have any threads looping in one of
their methods, once the thread -- the one that told the JTree to unsubscribe
from the composite model -- leaves the scope of the JTree, the composite
model and underlying model will no longer be reachable, and thus be
collectible.
- Oliver
Thomas Hawtin - 28 Oct 2005 21:19 GMT
>>>>When layering models like this, you need to be careful with listeners.
>>>>You should make sure when the model nearest the component has no
[quoted text clipped - 19 lines]
>
> I don't understand what you mean by inner classes.
http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.1.3
Listeners are implemented as inner classes the vast majority of the
time. Often anonymous inner classes.
> For now I'm assuming
> this has something to do with Sun's implementation of listeners that you
[quoted text clipped - 4 lines]
> subscribing to it, that list is empty (i.e. it doesn't have references to
> any other object).
In the case of listening to input events, that's true. If I have an
action listener, there is no further information necessary to perform
the action. In some circumstances you might want to reduce the class
count and use the event source to distinguish between a series of actions.
In the case of listeners to state change events, there isn't enough
information to do anything useful. If you want to repaint a tree, you
need to go back to the tree model and get values for each of the showing
nodes.
You also need a reference to the observed object in order to remove the
listeners.
> (I'm also not sure I understand the significance and distinction between
> the upper and lower arrows).
The leftward (upper) arrows represent an indirect strong reference, via
a listener, from the observed/publisher/event source to the interested
object. The rightward (lower) arrows represent the direct strong
reference from the interested object to the observed/publisher/event source.
>>The JTree and composite model are all about a single display. Suppose the
>>underlying model is longer lived. Removing the composite model from the
[quoted text clipped - 13 lines]
> model and underlying model will no longer be reachable, and thus be
> collectible.
Often the underlying model will have a longer lifetime. If this is the
case, then the observing model will still be strongly reachable, after
it has server its useful lifetime. Memory leak.
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/