Skip to content

test: Add GC lifecycle test for identity-cached wrappers#731

Merged
kateinoigakukun merged 1 commit intomainfrom
feat/identity-gc-lifecycle-test-v2
Apr 28, 2026
Merged

test: Add GC lifecycle test for identity-cached wrappers#731
kateinoigakukun merged 1 commit intomainfrom
feat/identity-gc-lifecycle-test-v2

Conversation

@krodak
Copy link
Copy Markdown
Member

@krodak krodak commented Apr 28, 2026

Overview

Add a test verifying that the WeakRef-based identity cache (introduced in #723) does not prevent garbage collection of Swift heap objects.

The existing GC lifecycle test (testJSWrapperIsDeallocatedAfterFinalization in SwiftClassSupportTests) covers non-identity classes. This adds an equivalent for @JS(identityMode: true) classes where the identity cache holds a WeakRef to the wrapper.

What it tests

Creates a RetainLeakSubject (identity-mode class), crosses it to JS 5 times (filling the identity cache with a WeakRef entry), drops all Swift-side references, triggers GC + event loop ticks, and verifies:

  • The Swift object is deallocated (weakSubject == nil)
  • deinit fires exactly once

This covers the scenario where only JavaScript holds a reference to an identity-cached Swift object via WeakRef, then that reference becomes unreachable.

What changed

  • IdentityModeTests.swift — Added testIdentityCachedWrapperIsReclaimedByGC async test. Added @JSFunction gc() import (same pattern as SwiftClassSupportTests).
  • Generated/BridgeJS.swift + Generated/JavaScript/BridgeJS.json — Regenerated to include gc import binding.

Verify that WeakRef-based identity cache does not prevent garbage collection.
Creates an identity-mode object, crosses it 5 times (filling identity cache),
drops all references, triggers GC + event loop ticks, and asserts the Swift
object is deallocated and deinit fires exactly once.
@krodak krodak requested a review from kateinoigakukun April 28, 2026 10:26
@krodak krodak self-assigned this Apr 28, 2026
@kateinoigakukun kateinoigakukun merged commit 016fa5b into main Apr 28, 2026
13 checks passed
@kateinoigakukun kateinoigakukun deleted the feat/identity-gc-lifecycle-test-v2 branch April 28, 2026 22:52
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.

2 participants