RFR: 8275720: CommonComponentAccessibility.createWithParent isWrapped causes mem leak

Anton Tarasov ant at openjdk.java.net
Fri Oct 22 16:51:11 UTC 2021


On Fri, 22 Oct 2021 16:02:32 GMT, Anton Tarasov <ant at openjdk.org> wrote:

> This is a reimplementation of the `isWrapped` logic in the method:
> 
> `+[CommonComponentAccessibility createWithParent:accessible:role:index:withEnv:withView:isWrapped:]`
> 
> The `isWrapped` arg was used to create an a11y element which is wrapped into an object that does not have direct peer in Java (like `ListRowAccessibility`, `TableRowAccessibility`). The problem is that such objects leak, because when the wrapped element is created (`isWrapped == YES`), the native pointer to the element is rewritten in the associated java peer (the `accessible` arg) and the element object is then released via the `CFRetainedResource` mechanism. However the wrapping object (`ListRowAccessibility`, `TableRowAccessibility`) is never released.
> 
> This fix proposes a dedicated class for creating such paired objects, where a wrapper object releases its wrapped child when the deallocation is triggered by garbage collecting the associated java peer.

src/java.desktop/macosx/native/libawt_lwawt/awt/a11y/CellAccessibility.m line 38:

> 36: }
> 37: 
> 38: - (NSArray *)accessibilityChildren

The `accessibilityChildren` method is now inherited from `ComponentWrapperAccessibility`.

src/java.desktop/macosx/native/libawt_lwawt/awt/a11y/ColumnAccessibility.m line 52:

> 50: }
> 51: 
> 52: - (NSArray *)accessibilityChildren

By removing this method I'm duplicating the change proposed in ttps://github.com/openjdk/jdk/pull/6020. So this fix should be merged after the referred commit is integrated.

src/java.desktop/macosx/native/libawt_lwawt/awt/a11y/ListRowAccessibility.m line 41:

> 39: }
> 40: 
> 41: - (NSArray *)accessibilityChildren

The method is now inherited.

src/java.desktop/macosx/native/libawt_lwawt/awt/a11y/TableRowAccessibility.m line 99:

> 97:                                                       withView:self->fView];
> 98: 
> 99:             [childrenCells addObject:child];

Here we create a wrapping object and we rely on the default release logic, so we do not need to additionally retain/release it.

-------------

PR: https://git.openjdk.java.net/jdk/pull/6081



More information about the client-libs-dev mailing list