Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find/replace overlay: clean up PreferenceChangeListener #1948

Merged
merged 1 commit into from
Jun 10, 2024

Conversation

Wittmaxi
Copy link
Contributor

The PreferenceChangeListener now starts listening when an Overlay was created and stops listening once the Overlay is disposed of. Fixes a previous resource leak.

fixes jdt#1444

The PreferenceChangeListener now starts listening when an Overlay was
created and stops listening once the Overlay is disposed of. Fixes a
previous resource leak.

fixes jdt#1444
@Wittmaxi
Copy link
Contributor Author

@jukzi can you please look into this and tell me whether it improves things? When/How are the resource-leak tests ran?

@jukzi
Copy link
Contributor

jukzi commented Jun 10, 2024

@jukzi can you please look into this and tell me whether it improves things? When/How are the resource-leak tests ran?

I did not know how to reproduce the test error locally so i can not verify locally if it is solved.
But the idea of the test is that there should be no object leaked - which can be better manually tested with a tool like VisualVm comparing heapDump snapshot before/after

Copy link
Contributor

Test Results

 1 210 files   -   605   1 210 suites   - 605   1h 3m 30s ⏱️ - 27m 37s
 7 636 tests ±    0   7 405 ✅  -     3  231 💤 +  3  0 ❌ ±0 
16 046 runs   - 8 023  15 533 ✅  - 7 787  513 💤  - 236  0 ❌ ±0 

Results for commit 7abb920. ± Comparison against base commit 385b30b.

This pull request skips 3 tests.
UiTestSuite org.eclipse.ui.tests.api.ApiTestSuite org.eclipse.ui.tests.api.WorkbenchPluginTest ‑ testGetImageRegistryFromAdditionalDisplay
org.eclipse.jface.text.tests.contentassist.ContextInformationTest ‑ testContextInfo_hide_focusOut
org.eclipse.urischeme.internal.registration.TestUnitWinRegistry ‑ testWinRegistry


FindReplaceOverlayFirstTimePopup.displayPopupIfNotAlreadyShown(shellToUse);
}

overlay.setPositionToTop(shouldPositionOverlayOnTop());
overlay.open();
overlay.getShell().addDisposeListener(__ -> removeDialogPreferenceListener());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't be better to move overlayDialogPreferenceListener to the FindReplaceOverlay itself? There one could simply add listener in constructor and remove on close().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had moved this listener out of the FindReplaceOverlay as a response to @HeikoKlare's comment: #1192 (comment)

I believe that he is right and believe that it is indeed best if the Overlay is independent from the "global parametrization".

@iloveeclipse
Copy link
Member

I did not know how to reproduce the test error locally so i can not verify locally if it is solved.

Just start the test from IDE as any other test, it will fail saying that JVM args should be modified, so proceed and add all the javavmargs arguments from eclipse.jdt.ui/org.eclipse.jdt.ui.tests/test.xml to the JVM arguments launch config section.
Eventually you should remove all non-standard bundles from the launch config (e.g. I had to remove spotbugs as the test can't find some class referenced in one of its dependencies).

This change fixes the leak, but as said above, I would prefer the listener would be moved from the action to the overlay class so no memory leak should happen by design.

@Wittmaxi
Copy link
Contributor Author

@iloveeclipse the leak does NOT happen in the find/replace overlay. The leak happens because I am not notified when the Action is disposed of and since the PreferenceChangeListeners is a field of the Action, I could not know when it was destroyed.

@iloveeclipse
Copy link
Member

@iloveeclipse the leak does NOT happen in the find/replace overlay.

Sure, I never said that. What I mean is that if you would move listener from the action to the overlay, no leak would happen.

The leak happens because I am not notified when the Action is disposed of and since the PreferenceChangeListeners is a field of the Action, I could not know when it was destroyed.

Right, but why should action listen to overlay preferences in first place, if it's what the overlay should care about.
@HeikoKlare : not sure why you didn't want listener to be in the overlay class. Could you please check this bug?

@Wittmaxi
Copy link
Contributor Author

@iloveeclipse a leak would still happen: the listener is attached to the Preferences object of Eclipse, the Overlay still would have to implement it's own "dispose"-method which then disposes of this listener.

The action parametrizes the overlay as it is the "consumer" of the overlay.
Imagine in the future you have a specific type of View which wants to use the Overlay (which is something we are aiming for) but needs the overlay to be at the bottom - it would have to be able to disregard global parametrization of the Overlay.

@laeubi
Copy link
Contributor

laeubi commented Jun 10, 2024

@Wittmaxi can you explain where / why you need to listen to preference changes? Maybe one can solve it without a listener or using the listener on a different place...

@Wittmaxi
Copy link
Contributor Author

@laeubi When changing the Overlay preferences from "display overlay on top" to "display overlay on bottom", I want to be able to instantly display the overlay on the bottom without needing to close/re-open the overlay

@iloveeclipse is it okay for you if we create an issue to discuss this a bit later down the line (when Heiko is back from Vacation)? For now, I believe that it is most important to fix the JavaLeakTest, the design decision of "who is responsible for parametrizing the overlay?" is out of scope for this PR.

@jukzi
Copy link
Contributor

jukzi commented Jun 10, 2024

Just start the test from IDE as any other test, it will fail saying that JVM args should be modified, so proceed and add all the javavmargs arguments from eclipse.jdt.ui/org.eclipse.jdt.ui.tests/test.xml to the JVM arguments launch config section.

i did that but the test was green for me locally.

@iloveeclipse
Copy link
Member

i did that but the test was green for me locally.

Haven't checked the code, might be something not possible to test on Windows.

is it okay for you if we create an issue to discuss this a bit later down the line (when Heiko is back from Vacation)? For now, I believe that it is most important to fix the JavaLeakTest, the design decision of "who is responsible for parametrizing the overlay?" is out of scope for this PR.

OK

@iloveeclipse iloveeclipse merged commit 5179e72 into eclipse-platform:master Jun 10, 2024
15 of 16 checks passed
@HeikoKlare
Copy link
Contributor

@HeikoKlare : not sure why you didn't want listener to be in the overlay class. Could you please check this bug?

is it okay for you if we create an issue to discuss this a bit later down the line (when Heiko is back from Vacation)? For now, I believe that it is most important to fix the JavaLeakTest, the design decision of "who is responsible for parametrizing the overlay?" is out of scope for this PR.

If I recap correctly, the reason for not wanting the preference listener in the FindReplaceOverlay is that this would unnecessarily tie the FindReplayOverlay to the according preference and thus a specific paramerization mechanism. This has several drawbacks, just to mention some of them:

  1. As a very general remark, it introduces an unnecessary dependency and coupling.
  2. It increases the number of responsibilities of the class (by also making it care about its own parameterization), while the class is too complex already now.
  3. It makes the class parameterize itself instead of allowing its parametrization by consumers. This reduces its reusability and is usually rather an antipattern in terms of properly assigning responsibilities.
  4. It reduces/complicates testability as it makes the class depend on some global parameterization state.

Anyway, is this still an open point for discussion and has the solution implemented so far to be revised or it okay for everyone?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants