Skip to content

Reuse and close Android barcode scanners without leaking shared images - #813

Open
zack-dev-cm wants to merge 1 commit into
teslamotors:masterfrom
zack-dev-cm:fix/barcode-scanner-lifecycle
Open

zack-dev-cm wants to merge 1 commit into
teslamotors:masterfrom
zack-dev-cm:fix/barcode-scanner-lifecycle

Conversation

@zack-dev-cm

@zack-dev-cm zack-dev-cm commented Sep 14, 2026 •

Copy link
Copy Markdown

Summary

Fixes #811. The Android analyzer creates an ML Kit scanner for every frame without closing it. The shared barcode/face callback can also leave an image open when a consumer throws synchronously. Both defects reproduce in the original native implementation; a standard-template reproducer uses published version 18.0.1.

Give each barcode analyzer one lazy scanner and an explicit close lifecycle. Rebinding or detaching closes it after outstanding work settles; closed analyzers suppress late events. Launch both shared-image consumers even if one throws synchronously, then close the image exactly once after all launched tasks finish. Public constructors, analysis entry points, inference frequency and event throttling are preserved.

This PR starts independently from upstream. Coordinate mapping is in #812, executor reattachment in #817, and CI toolchain drift in #816.

How did you test this change?

Independent head 81914f5, based on a2a81ce:

  • Original native implementation: three intended failures and four passing controls.
  • Both React Native architectures: 21 Kotlin/Robolectric tests pass without skips; TypeScript and ESLint pass.
  • An installed npm archive builds release/test APKs after native-source verification. Real ML Kit on Android 29 processes synthetic YUV images across 20 sessions: 20 scanner creations/closes, 60 image submissions/closes, exactly 40 events, and no events from closing sessions.
  • The unchanged Android example completes three barcode-screen mount/return cycles with image-file camera input and the JavaScript callback. The installed iOS example completes three mount/return cycles on an iOS 26.2 simulator.
  • The earlier #812/#813 integration passes 38 combined Robolectric tests and both installed ML Kit test classes in both architectures.

The four-PR merge guide identifies the overlapping files and the exact resolution at 7ffe27b. Its public validation passes 41 Robolectric tests with zero skips, TypeScript, ESLint and installed Debug AAR builds in both architectures; per-suite summaries and artifacts are available.

Upstream workflows await approval. Synthetic lifecycle tests do not establish physical-camera memory, battery or performance improvements. The simulator checks exercise navigation. The baseline default-Xcode build failure is addressed separately in #816.

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.

Android barcode analyzer allocates an unclosed scanner per frame and can leak shared images

1 participant