Stop leaking the remaining JS ArrayBuffers passed to Java

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>
This commit is contained in:
James BabcockandClaude Opus 5.5 committed 2026-09-25 22:28:45 -07:00
1 parent 8cdee83ff4
commit 1812818ae2
12 files changed
+72 -25

No files matched your search

+12 -1
View File
@@ -1,7 +1,7 @@
const test = require("node:test");
const assert = require("node:assert/strict");
const { JavaDirectBuffer } = require("../.test-build/app/native/java-direct-buffer.js");
const { JavaDirectBuffer, copyToJavaByteBuffer } = require("../.test-build/app/native/java-direct-buffer.js");
/**
* A stand-in for java.nio.ByteBuffer.allocateDirect: fixed capacity, a
@@ -109,3 +109,14 @@ test("a view on a larger buffer contributes only its own bytes", () => {
const view = whole.subarray(10, 30);
assert.deepEqual(consume(pool.load(view), 20), whole.slice(10, 30));
});
test("copyToJavaByteBuffer gives each crossing its own exact-length buffer", () => {
const backend = fakeBackend();
const whole = frame(100, 5);
const first = copyToJavaByteBuffer(whole.subarray(10, 30), backend);
const second = copyToJavaByteBuffer(frame(7, 1), backend);
assert.notEqual(first, second);
assert.deepEqual(consume(first, 20), whole.slice(10, 30));
assert.deepEqual(consume(second, 7), frame(7, 1));
assert.equal(consume(copyToJavaByteBuffer(new Uint8Array(0), backend), 0).length, 0);
});