Skip to content

Commit 2611aaa

Browse files
committed
Use WeakListeners in ApplicationDescriptor implementations to prevent leaks when models are cleared.
1 parent cc0ef29 commit 2611aaa

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

visualvm/application/src/org/graalvm/visualvm/application/ApplicationDescriptor.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.beans.PropertyChangeSupport;
3737
import org.graalvm.visualvm.core.datasupport.Stateful;
3838
import org.graalvm.visualvm.core.datasupport.Utils;
39+
import org.openide.util.WeakListeners;
3940

4041
/**
4142
* DataSourceDescriptor for Application.
@@ -98,11 +99,12 @@ public boolean providesProperties() {
9899

99100

100101
protected void setApplicationType(ApplicationType type) {
101-
if (this.type != null) this.type.removePropertyChangeListener(this);
102+
// if (this.type != null) this.type.removePropertyChangeListener(this);
102103

103104
this.type = type;
104105

105-
this.type.addPropertyChangeListener(this);
106+
this.type.addPropertyChangeListener(WeakListeners.propertyChange(this, this.type));
107+
// this.type.addPropertyChangeListener(this);
106108
}
107109

108110
protected ApplicationType getApplicationType() {

visualvm/jmx/src/org/graalvm/visualvm/jmx/impl/JmxApplicationDescriptor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.graalvm.visualvm.core.datasupport.Stateful;
3838
import org.graalvm.visualvm.core.datasupport.Utils;
3939
import org.openide.util.ImageUtilities;
40+
import org.openide.util.WeakListeners;
4041

4142
/**
4243
*
@@ -51,7 +52,8 @@ public class JmxApplicationDescriptor extends ApplicationDescriptor {
5152
protected JmxApplicationDescriptor(JmxApplication application) {
5253
super(application, resolveApplicationType(application), resolvePosition(application, POSITION_AT_THE_END, true));
5354

54-
application.addPropertyChangeListener(Stateful.PROPERTY_STATE, this);
55+
application.addPropertyChangeListener(Stateful.PROPERTY_STATE, WeakListeners.propertyChange(this, Stateful.PROPERTY_STATE, application));
56+
// application.addPropertyChangeListener(Stateful.PROPERTY_STATE, this);
5557
}
5658

5759
public boolean supportsRename() {

0 commit comments

Comments
 (0)