The same NativeScript conversion leak as the frame path (see
java-direct-buffer.ts) applied to every other ArrayBuffer handed to a
Java ByteBuffer parameter:
- Shell scenes (submitShellScene on the bridge and the preview display),
submitted on every shell render, which the frame-path fix predates.
These now go through a reused JavaDirectBuffer like frames do.
- Glyph, firmware-glyph and image atlas registration, Mapbox image
decode, the preview placeholder bitmap, firmware hash/write, binary
file writes and the EvenHub privacy-policy download, plus the Kotlin
protocol smoke test. These are rare or large, so they cross through a
new copyToJavaByteBuffer: a fresh Java direct buffer per call that is
freed normally, rather than one pinned for the life of the isolate.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Passing a JS ArrayBuffer to a Java ByteBuffer parameter leaks it in
@nativescript/android 9.0.4 through 9.1.1: JsArgConverter wraps the backing store with
NewDirectByteBuffer and takes a JNI global ref that it never deletes. The
ref keeps the ByteBuffer reachable, so makeInstanceWeakAndCheckIfAlive
always answers "alive", the JS finalizer re-arms, and V8 never frees the
ArrayBuffer. submitSurfaceFrame passed a fresh copy of each frame this way,
so every frame leaked a full surface (576x260, 640x452 or 640x480 bytes)
plus one global ref, including frames that Java then discards as unchanged.
The draw-list buffer and buzzer payloads leaked the same way.
Each payload now goes through a reused Java direct ByteBuffer
(app/native/java-direct-buffer.ts): JS writes into it through an
ArrayBuffer.from view, and the Java object itself is passed, which takes
NativeScript's ordinary object path. Every consumer (SurfaceCompositor
applyAndComposite, playBuzzerSequence) copies before returning, so one
buffer per JS context is safe.
Covered: the communicator bridge (frames, draw lists, buzzer, which also
carries EvenHub tones), the preview-only display, and all eight worker
apps. Workers submit through the Android getActiveDisplay() (frames) and
worker-buzzer (tones), so the reused buffers live there rather than in
each worker; the worker sources are shared with iOS, whose active display
takes the ArrayBuffer itself. The
smaller one-off crossings (glyph and image atlas registration, the gray
preview helper, firmware and file writes) are left as they are.
tests/java-direct-buffer.test.cjs covers the helper against a fake
ByteBuffer, and the Android worker-buzzer test stubs it.
(Rebased onto main by James Babcock: worker changes moved into
active-display.ts and worker-buzzer.ts.)
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
<details>
<summary>Prompts Used</summary>
User: This checkout corresponds to https://github.com/jimrandomh/faceclaw/pull/27. Review this branch.
GPT-6 Astra:
> Found one issue:
>
> - **[P2] Wait for Whisper’s final result before completing dictation** — [FaceclawVoiceController.java:729](/Users/jbabcock/repositories/g2/faceclaw/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawVoiceController.java:729). Skipping partial decodes leaves short utterances without text until release, but the dialog still finalizes after its existing timeout. If decoding exceeds roughly 2.7 seconds (native stop’s 1.5-second wait plus the dialog’s 1.2-second timeout), auto-send can abandon a short command or send an incomplete longer one. Continue can append the late editing instruction literally instead of refining the message. I reproduced these outcomes with delayed transcript events. These flows should await recognition completion.
>
> Validation: TypeScript and a clean Android build passed. All 21 test failures also occur on `main`. Actual Whisper latency was not tested on hardware.
<hr>
User: Thanks, let's fix that issue.
GPT-6 Astra:
> Fixed. Dictation now waits for native recognition to finish before fallback timers run. Auto-send, Continue, and AI Chat preserve delayed Whisper results; cancellation ignores late transcripts.
>
> TypeScript and Android builds pass. All 11 new regression tests pass. The full suite still has the same 21 pre-existing failures.
</details>