Christopher Brind wrote: > Since treeData is private, why not use a WeakReference? > http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ref/WeakReference.html > > > WeakReferences are not a solution, because the application developer might not keep a reference to treeData, which means the TreeView would mysteriously lose it's connection to the data object when GC next runs. > 2009/3/13 Greg Brown <gkbr...@mac.com> > > >> 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. >> >> Swing has hierarchy listeners which allow a component to do this. >> 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? >> >> In Swing, it is not at all normal to keep a reference to the model object after you have removed a component from the view hierarchy, so Swing doesn't do anything.
In general, I don't expect this to be much of a problem. This is pretty much a corner case. Applications that dynamically build their user interfaces, or recreate their user interfaces will just have to get used to explicitly disconnecting the model from the component, in much the same way that I currently have to explictly disconnect listeners from Swing components. Regards, Noel Grandin.