Skip to content

Generate -dealloc methods for Java records in DestructorGenerator. - #2943

Merged
copybara-service[bot] merged 1 commit into
masterfrom
test_1026634573
Nov 20, 2026
Merged

copybara-service[bot] merged 1 commit into
masterfrom
test_1026634573

Conversation

@copybara-service

Copy link
Copy Markdown

Generate -dealloc methods for Java records in DestructorGenerator.

DestructorGenerator previously overrode endVisit(AnnotationTypeDeclaration)
and endVisit(TypeDeclaration) but omitted endVisit(RecordDeclaration).
Because RecordDeclaration extends AbstractTypeDeclaration directly, J2ObjC
never generated - (void)dealloc for Java record types. Under manual
reference counting (-use-reference-counting), record constructors retain
non-primitive component fields via JreStrongAssign, so every object-typed
component leaked on deallocation. Under ARC/strict-field-assign, this also
skipped JreStrictFieldStrongRelease, finalize, and @OnDealloc hooks on
records.

Add endVisit(RecordDeclaration) delegating to addDeallocMethod(node) and
add unit tests in DestructorGeneratorTest covering MRC, ARC,
strict-field-assign, primitive-only records, @Weak, @RetainedWith,
static fields, @OnDealloc/finalize(), nested/local records, and generic
records with compact constructors.

`DestructorGenerator` previously overrode `endVisit(AnnotationTypeDeclaration)`
and `endVisit(TypeDeclaration)` but omitted `endVisit(RecordDeclaration)`.
Because `RecordDeclaration` extends `AbstractTypeDeclaration` directly, J2ObjC
never generated `- (void)dealloc` for Java `record` types. Under manual
reference counting (`-use-reference-counting`), record constructors retain
non-primitive component fields via `JreStrongAssign`, so every object-typed
component leaked on deallocation. Under ARC/strict-field-assign, this also
skipped `JreStrictFieldStrongRelease`, `finalize`, and `@OnDealloc` hooks on
records.

Add `endVisit(RecordDeclaration)` delegating to `addDeallocMethod(node)` and
add unit tests in `DestructorGeneratorTest` covering MRC, ARC,
`strict-field-assign`, primitive-only records, `@Weak`, `@RetainedWith`,
`static` fields, `@OnDealloc`/`finalize()`, nested/local records, and generic
records with compact constructors.

PiperOrigin-RevId: 1026801600
@copybara-service
copybara-service Bot merged commit d7d6c18 into master Nov 20, 2026
2 checks passed
@copybara-service
copybara-service Bot deleted the test_1026634573 branch November 20, 2026 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant