Skip to content

feat(android): add ArrayBuffer.close() - #2001

Open
mrousavy wants to merge 1 commit into
v1from
mrousavy/kotlin-arraybuffer-close
Open

mrousavy wants to merge 1 commit into
v1from
mrousavy/kotlin-arraybuffer-close

Conversation

@mrousavy

Copy link
Copy Markdown
Member

Kotlin ArrayBuffer now implements AutoCloseable. close() resets its HybridData, so buffer.use { } releases native or JS-backed memory right away instead of waiting for the Java GC. Other owners (JS, C++) keep the memory until they release it too.

  • Accessing a closed buffer throws an IllegalStateException. Debug builds also throw a clear error when a closed buffer is passed to JS or C++.
  • Adds an isClosed property.

I left the generated JNI bridge alone instead of closing JS-backed parameters after a synchronous call. A JS-backed ArrayBuffer keeps its JS object alive, so C++ and Swift implementations can store one and return it later on the JS thread. Closing it automatically would break that in Kotlin.

close() isn't observable from JS by itself. The wrap(..., onDelete) PR in this stack adds shared tests where the Kotlin fixture releases its reference with close().

Tested on an API 36 emulator: the array-buffers runtime suite passes with this PR alone.

🤖 Generated with Claude Code

Kotlin ArrayBuffer now implements AutoCloseable. close() releases the
native or JS-backed memory right away instead of waiting for the Java GC.
Later access throws an IllegalStateException, and debug builds throw a
clear error when a closed buffer is passed to JS or C++.
@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 changed the base branch from v1 to main October 23, 2026 12:36
@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 changed the base branch from main to v1 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 — 6a769e67 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