forked from Blendman974/faceclaw
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:
1 parent
8cdee83ff4
commit
1812818ae2
12 files changed
+72
-25
No files matched your search
@@ -1,17 +1,21 @@
|
||||
import { copyToJavaByteBuffer } from './java-direct-buffer'
|
||||
|
||||
declare const com: any
|
||||
|
||||
// Byte payloads cross as fresh Java buffers: passing a JS ArrayBuffer to Java
|
||||
// leaks it (java-direct-buffer.ts).
|
||||
|
||||
/** Android bridge to the process-wide shared Kotlin atlases. */
|
||||
export function textureAtlasAvailable(): boolean { return !!global.isAndroid }
|
||||
export function textureFontId(key: string): number { return com.faceclaw.app.GlyphAtlas.fontId(key) }
|
||||
export function registerTextureGlyphs(buffer: ArrayBuffer, aa: boolean): void {
|
||||
const reader = new com.faceclaw.app.AndroidByteReader(buffer)
|
||||
const reader = new com.faceclaw.app.AndroidByteReader(copyToJavaByteBuffer(new Uint8Array(buffer)))
|
||||
if (aa) com.faceclaw.app.GlyphAtlas.registerAa(reader)
|
||||
else com.faceclaw.app.GlyphAtlas.register(reader)
|
||||
}
|
||||
export function registerFirmwareGlyphs(buffer: ArrayBuffer): void {
|
||||
com.faceclaw.app.FwGlyphAtlas.register(new com.faceclaw.app.AndroidByteReader(buffer))
|
||||
com.faceclaw.app.FwGlyphAtlas.register(new com.faceclaw.app.AndroidByteReader(copyToJavaByteBuffer(new Uint8Array(buffer))))
|
||||
}
|
||||
export function textureImageId(key: string, width: number, height: number, pixels: Uint8Array): number {
|
||||
const buffer = pixels.byteOffset === 0 && pixels.byteLength === pixels.buffer.byteLength ? pixels.buffer : pixels.slice().buffer
|
||||
return com.faceclaw.app.ImageAtlas.ensure(key, width, height, new com.faceclaw.app.AndroidByteReader(buffer))
|
||||
return com.faceclaw.app.ImageAtlas.ensure(key, width, height, new com.faceclaw.app.AndroidByteReader(copyToJavaByteBuffer(pixels)))
|
||||
}
|
||||
Reference in new issue
Block a user