[kepler-dev] change proposal for ptolemy.vergil.tree.EntityTreeModel class.
Christopher Brooks
cxh at eecs.berkeley.edu
Mon Sep 20 18:14:48 PDT 2010
Hi Jianwu,
Your change looks ok to me. The diff between what you sent and what
is in the tree is below:
bash-3.2$ diff ~/Downloads/EntityTreeModelNew.java EntityTreeModel.java
30d29
< import java.lang.ref.WeakReference;
64c63
< public class EntityTreeModelNew implements TreeModel {
---
> public class EntityTreeModel implements TreeModel {
70c69
< public EntityTreeModelNew(NamedObj root) {
---
> public EntityTreeModel(NamedObj root) {
82c81
< _listenerList.add(new WeakReference(listener));
---
> _listenerList.add(listener);
176c175
< _listenerList.remove(new WeakReference(listener));
---
> _listenerList.remove(listener);
188c187
< TreeModelListener listener = (TreeModelListener) ((WeakReference)listeners.next()).get();
---
> TreeModelListener listener = (TreeModelListener) listeners.next();
263c262
< private List _listenerList = new LinkedList<WeakReference>();
---
> private List _listenerList = new LinkedList();
I folded in the change and added a comment:
/** Add a listener to this model.
* @param listener The listener to add.
* @see #removeTreeModelListener(TreeModelListener)
*/
public void addTreeModelListener(TreeModelListener listener) {
// In http://bugzilla.ecoinformatics.org/show_bug.cgi?id=4801,
// Jianwu Wang found that the _listenerList attribute in
// ptolemy.vergil.tree.EntityTreeModel was leaking memory.
// This attribute keeps holding some references, so that
// instances of EntityTreeModel and its sub-classes can not be
// GCed when a window is open and closed.
//
// When it and its sub-classes are used in Kepler,
// addTreeModelListener() and removeTreeModelListener()
// functions of EntityTreeModel class are called implicitly.
// Jianwu did not find a good way to clean up after a window
// is closed. Changing the _listenerList attribute using
// WeakReference fixe the leak.
_listenerList.add(new WeakReference(listener));
}
I updated the 8.0 release branch, thanks for the patch!
Derik, I think you would want this in the 2.1 release. I'm still working on deterimining
if ptolemy-8.0.0 is what should be shipped with Kepler 2.1.
_Christopher
On 9/20/10 4:27 PM, Jianwu Wang wrote:
> As I mentioned at http://bugzilla.ecoinformatics.org/show_bug.cgi?id=4801, I found one class might need to be changed for memory leak. It's the _listenerList attribute in
> ptolemy.vergil.tree.EntityTreeModel. One memory leak I'm tracing down is that this attribute keeps holding some references, so that instances of EntityTreeModel and its sub-classes can not be GCed
> when a window is open and closed.
>
> When it and its sub-classes are used in Kepler, addTreeModelListener() and removeTreeModelListener() functions of EntityTreeModel class are called implicitly. I haven't find good ways to clean
> up after a window is closed.
>
> If changing the _listenerList attribute using WeakReference, it will be able to fix the leak.
--
Christopher Brooks, PMP University of California
CHESS Executive Director US Mail: 337 Cory Hall
Programmer/Analyst CHESS/Ptolemy/Trust Berkeley, CA 94720-1774
ph: 510.643.9841 fax:510.642.2718 (Office: 545Q Cory)
home: (F-Tu) 707.665.0131 cell: 707.332.0670
More information about the Kepler-dev
mailing list