Re: can JTree's have multiple roots and models ?
- From: Thomas Hawtin <usenet@xxxxxxxxxxxxxxxxx>
- Date: Fri, 28 Oct 2005 19:26:28 +0100
Oliver Wong wrote:
"Thomas Hawtin" <usenet@xxxxxxxxxxxxxxxxx> wrote in message news:43617af8$0$6529$ed2619ec@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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 attached to it, it has no listeners attached to the underlying model(s). If you don't, you might find yourself with a small (or otherwise) memory leak.
I'm guessing the easy fix for this would be to have your "super TreeModel" register listeners on all of its sub TreeModels right away, and then never fiddle with the listeners from there on. Then, the super TreeModel receives an event from one of its sub TreeModels, it just forwards these events to its own registered listeners.
Would there be any problems with this implementation?
The problem is you have (strong) references set up as below (the upper arrows represent the references via listeners typically implemented as inner classes of some description).
<------ <------
JTree Composite model Underlying model
------> ------>The JTree and composite model are all about a single display. Suppose the underlying model is longer lived. Removing the composite model from the JTree should free up all the required memory, but you end up with:
<------
JTree Composite model Underlying model
------>The composite model (and anything it refers to) is not collectible. However if you composite model only adds listeners when it has listeners applied to itself, then you get:
JTree Composite model Underlying model ------>
The composite model is now collectible as it should be.
Tom Hawtin -- Unemployed English Java programmer http://jroller.com/page/tackline/ .
- References:
- can JTree's have multiple roots and models ?
- From: William Z.
- Re: can JTree's have multiple roots and models ?
- From: Oliver Wong
- Re: can JTree's have multiple roots and models ?
- From: William Z.
- Re: can JTree's have multiple roots and models ?
- From: Oliver Wong
- Re: can JTree's have multiple roots and models ?
- From: Thomas Hawtin
- can JTree's have multiple roots and models ?
- Prev by Date: Re: getParentDirectory
- Next by Date: Re: TableSorter reselect selected rows
- Previous by thread: Re: can JTree's have multiple roots and models ?
- Next by thread: Re: can JTree's have multiple roots and models ?
- Index(es):
Relevant Pages
|