Skip to content

feat(android): add ArrayBuffer.wrap(..., onDelete) - #2002

Open
mrousavy wants to merge 1 commit into
mrousavy/kotlin-arraybuffer-closefrom
mrousavy/kotlin-arraybuffer-wrap-on-delete
Open

mrousavy wants to merge 1 commit into
mrousavy/kotlin-arraybuffer-closefrom
mrousavy/kotlin-arraybuffer-wrap-on-delete

Conversation

@mrousavy

Copy link
Copy Markdown
Member

Adds ArrayBuffer.wrap(byteBuffer, onDelete) and ArrayBuffer.wrap(hardwareBuffer, onDelete), matching Swift's wrap(dataWithoutCopy:size:onDelete:) and C++'s ArrayBuffer::wrap(data, size, deleteFn). onDelete runs once the last owner (JS or native) has released the buffer, e.g. to close an Image, release a MediaCodec output buffer, or return a pooled buffer.

  • ByteBufferArrayBuffer and HardwareBufferArrayBuffer keep a global ref to a Runnable and run it from their destructor.
  • Hermes can destroy JS objects on its GC thread, which isn't attached to the JVM. The destructor attaches only when needed, like resetGlobalRef.
  • Errors thrown by onDelete go to the GlobalErrorHandler and don't terminate the app.

New shared cases in array-buffers.test.ts, implemented in the C++, Swift and Kotlin fixtures, check that a wrapped buffer is deleted exactly once, after both JS and native released it, in either order.

Tested with this PR alone: the array-buffers suite on an API 36 emulator and the full iOS runtime suite on an iOS 26.5 simulator pass.

🤖 Generated with Claude Code

Add ArrayBuffer.wrap(byteBuffer, onDelete) and a HardwareBuffer
overload, matching Swift's wrap(dataWithoutCopy:size:onDelete:) and C++'s
ArrayBuffer::wrap(data, size, deleteFn). onDelete runs once the last
owner released the buffer, so users can close an Image, release a
MediaCodec output buffer or return a pooled buffer.

The callback can run on Hermes' GC thread, so the destructor attaches only
when needed, and errors are reported to the GlobalErrorHandler.
@vercel

vercel Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
nitro-docs Ready Ready Preview Oct 23, 2026 12:37pm UTC

Request Review

@mrousavy
mrousavy added this pull request to stack #2005 October 23, 2026 12:37
@mrousavy
mrousavy removed this pull request from stack #2005 October 23, 2026 12:37
@mrousavy
mrousavy added this pull request to stack #2006 October 23, 2026 12:37
@mrousavy
mrousavy removed this pull request from stack #2006 October 23, 2026 17:52
@mrousavy
mrousavy added this pull request to stack #2007 October 23, 2026 17:52

This branch was successfully deployed

1 active deployment
Preview — 0b8e926b Deployed Oct 23, 2026 by vercel[bot]
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.

1 participant