On Wed, 22 Apr 2026 05:13:25 GMT, Jeremy Wood <[email protected]> wrote:
>> This PR automatically calls CAccessible.dispose() as Components are removed >> from the AWT hierarchy. >> >> I don't have a great understanding of this area of code / subject matter, >> but this appears to resolve #8381236. >> >> --------- >> - [x] I confirm that I make this contribution in accordance with the >> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai). > > Jeremy Wood has updated the pull request incrementally with one additional > commit since the last revision: > > 8381236: refactor proposed solution > > I still don't understand the life cycle of a CAccessible, but I'm starting > to think this simpler approach may be better. > > It seems like: > A. We never discard a CAccessible. Once CAccessible 'Y' is constructed, it > will forever be paired with (and referenced by) its AccessibleContext 'X'. > (Therefore the listeners that 'Y' installs never need to be uninstalled.) > B. Some external entity is defining `CAccessible#ptr`. We don't receive a > call to `setPtr`, and it's not defined during construction. But at some point > as VoiceOver interacts with a Swing app the `ptr` field is defined. > C. It appears safe to call `dispose()` repeatedly on the same CAccessible. > So in this way `dispose()` is like `Window.dispose()`: it releases resources, > but it can be reallocated later (by some external agent). (By contrast it is > NOT like `Graphics2D.dispose()`; subsequent attempts to use a Graphics2D will > fail after it has been disposed.) src/java.desktop/macosx/classes/sun/lwawt/macosx/CAccessible.java line 93: > 91: if (accessible instanceof Component component) { > 92: addNotificationListeners(component); > 93: component.addPropertyChangeListener("ancestor", (e) -> { My only question is: you are registering a new listener but when this listener is being removed? I understand that this happens in the CAccessible constructor and under normal circumstances component has only one CAccessible but that can change and in this case wouldn't it be a potential memory leak? ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/30578#discussion_r3140467622
