|
1 | 1 | /******************************************************************************* |
2 | | - * Copyright (c) 2003, 2022 IBM Corporation and others. |
| 2 | + * Copyright (c) 2003, 2025 IBM Corporation and others. |
3 | 3 | * |
4 | 4 | * This program and the accompanying materials |
5 | 5 | * are made available under the terms of the Eclipse Public License 2.0 |
@@ -152,7 +152,11 @@ protected void addListeners() { |
152 | 152 |
|
153 | 153 | @Override |
154 | 154 | protected void removeListeners() { |
155 | | - PDECore.getWorkspace().removeResourceChangeListener(this); |
| 155 | + IWorkspace workspace = PDECore.getWorkspace(); |
| 156 | + if (bundleRootChangedListener != null) { |
| 157 | + Arrays.stream(workspace.getRoot().getProjects()).forEach(this::removeBundleRootChangedListener); |
| 158 | + } |
| 159 | + workspace.removeResourceChangeListener(this); |
156 | 160 | super.removeListeners(); |
157 | 161 | } |
158 | 162 |
|
@@ -198,6 +202,9 @@ public boolean visit(IResourceDelta delta) throws CoreException { |
198 | 202 | if (addedOrOpened && bundleRootChangedListener != null) { |
199 | 203 | addBundleRootChangedListener(project); |
200 | 204 | } |
| 205 | + if (delta.getKind() == IResourceDelta.REMOVED && bundleRootChangedListener != null) { |
| 206 | + removeBundleRootChangedListener(project); |
| 207 | + } |
201 | 208 | if (isInterestingProject(project) && addedOrOpened) { |
202 | 209 | createModel(project, true); |
203 | 210 | return false; |
@@ -227,6 +234,13 @@ private void addBundleRootChangedListener(IProject project) { |
227 | 234 | pdeNode.addPreferenceChangeListener(bundleRootChangedListener); |
228 | 235 | } |
229 | 236 |
|
| 237 | + private void removeBundleRootChangedListener(IProject project) { |
| 238 | + IEclipsePreferences pdeNode = new ProjectScope(project).getNode(PDECore.PLUGIN_ID); |
| 239 | + // Remove the preference change listener when the project is removed |
| 240 | + // from the workspace to make it eligible for garbage collection |
| 241 | + pdeNode.removePreferenceChangeListener(bundleRootChangedListener); |
| 242 | + } |
| 243 | + |
230 | 244 | protected IPreferenceChangeListener createBundleRootChangeListener() { |
231 | 245 | return e -> { |
232 | 246 | if (PDEProject.BUNDLE_ROOT_PATH.equals(e.getKey()) && !isInRemovedBranch(e.getNode())) { |
|
0 commit comments