René's URL Explorer Experiment


Title: fix: stop leaking a JNI global ref per ArrayBuffer passed to Java by dpwhittaker · Pull Request #2062 · NativeScript/android · GitHub

Open Graph Title: fix: stop leaking a JNI global ref per ArrayBuffer passed to Java by dpwhittaker · Pull Request #2062 · NativeScript/android

X Title: fix: stop leaking a JNI global ref per ArrayBuffer passed to Java by dpwhittaker · Pull Request #2062 · NativeScript/android

Description: Description When a JS ArrayBuffer, SharedArrayBuffer or typed array crosses to Java for the first time, JsArgConverter::ConvertArg wraps it in a direct ByteBuffer, then calls env.NewGlobalRef(buffer) and never deletes the result. JsArgToArrayConverter::ConvertArg has the same code, and is used for Java array elements, overload resolution and values returned to Java. GetOrCreateObjectId already registers the buffer in the runtime's strong instances for as long as the JS object lives, so the extra reference does nothing except pin the buffer. Two consequences: Every distinct buffer stays in the JNI global reference table for the life of the process. ART aborts once the table holds 51,200 entries: JNI ERROR (app bug): global reference table overflow (max=51200), and the dump shows ~50,000 java.nio.DirectByteBuffer entries. The ArrayBuffer behind each pinned buffer is never freed either. JSObjectFinalizer keeps a JS object alive while its Java counterpart is alive, and the pinned DirectByteBuffer never dies. Passing the same ArrayBuffer again doesn't leak, because the existing link is reused. So the leak is one reference per distinct buffer. That matters for any app that hands Java a fresh buffer per event. We hit it in an app that passes each display frame (pixels plus glyph data) to Java as new ArrayBuffers. It aborted after 2.75 to 10.6 hours of use, at 1.4 GB RSS. The fix removes the NewGlobalRef call in both converters. Does your pull request have unit tests? Yes. Two tests in byte-buffer-test.js each pass 60,000 fresh buffers to Java, more than the table can hold: one as method arguments (alternating ArrayBuffer and Uint8Array), one as Java array elements. Run on a Galaxy Z Fold7 (arm64, Android 17) with the runtime built from this branch: Unpatched This branch New tests test app aborts with the overflow (50,398 DirectByteBuffer global refs) pass, ~0.5 s each Full test-app suite 1242 tests, 0 failures (without the new tests) 1244 tests, 0 failures Also checked in the affected app, by heap-dumping it and counting JNI global roots: Fresh buffers: after passing 1,000 fresh buffers to Java, there are no new JNI-global DirectByteBuffers. Unpatched, there were +1,000, and they survived a forced gc(). Collection: after JS and Java GC cycles, the 1,000 buffers are collected. Unpatched, they never were. Contents: 60,000 fresh buffers with known contents hash correctly on the Java side. Kept buffers: a buffer kept alive in JS still hashes correctly after the GC cycles. 🤖 Generated with Claude Code Summary by CodeRabbit Bug Fixes Improved handling of large numbers of JavaScript buffers passed to Java, preventing them from exhausting the runtime’s reference limit. Buffers remain accessible to Java while their JavaScript objects are still in use.

Open Graph Description: Description When a JS ArrayBuffer, SharedArrayBuffer or typed array crosses to Java for the first time, JsArgConverter::ConvertArg wraps it in a direct ByteBuffer, then calls env.NewGlobalRef(buffe...

X Description: Description When a JS ArrayBuffer, SharedArrayBuffer or typed array crosses to Java for the first time, JsArgConverter::ConvertArg wraps it in a direct ByteBuffer, then calls env.NewGlobalRef(buffe...

Opengraph URL: https://github.com/NativeScript/android/pull/2062

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:a2c4c9f9-3334-5bf4-938c-f733f8ebbd50
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idD4BA:2F4BD9:17885A9:1F078A1:6B0135D4
html-safe-noncebb8810c99c3c5fd4486861ce7ff3fd5d0eaf4ef807e81ac959371a738b539526
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENEJBOjJGNEJEOToxNzg4NUE5OjFGMDc4QTE6NkIwMTM1RDQiLCJ2aXNpdG9yX2lkIjoiNjE0MTQ1NzYzNTIxNDEwNTE2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmaccced90e3c1a36bbf9f39fa8e8614a2ae5fcc8d4afec26bcfba98793f82610b8e
hovercard-subject-tagpull_request:4737667260
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/NativeScript/android/pull/2062/files
twitter:imagehttps://avatars.githubusercontent.com/u/3069027?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/3069027?s=400&v=4
og:image:altDescription When a JS ArrayBuffer, SharedArrayBuffer or typed array crosses to Java for the first time, JsArgConverter::ConvertArg wraps it in a direct ByteBuffer, then calls env.NewGlobalRef(buffe...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/NativeScript/android git https://github.com/NativeScript/android.git
octolytics-dimension-user_id7392261
octolytics-dimension-user_loginNativeScript
octolytics-dimension-repository_id29137950
octolytics-dimension-repository_nwoNativeScript/android
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id29137950
octolytics-dimension-repository_network_root_nwoNativeScript/android
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/NativeScript/android/pull/2062/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FNativeScript%2Fandroid%2Fpull%2F2062%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FNativeScript%2Fandroid%2Fpull%2F2062%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=NativeScript%2Fandroid
Reloadhttps://github.com/NativeScript/android/pull/2062/files
Reloadhttps://github.com/NativeScript/android/pull/2062/files
Reloadhttps://github.com/NativeScript/android/pull/2062/files
NativeScripthttps://github.com/NativeScript
androidhttps://github.com/NativeScript/android
Codehttps://github.com/NativeScript/android
Issues106 (106)https://github.com/NativeScript/android/issues
Pull requests24 (24)https://github.com/NativeScript/android/pulls
Actionshttps://github.com/NativeScript/android/actions
Projectshttps://github.com/NativeScript/android/projects
Wikihttps://github.com/NativeScript/android/wiki
Security and qualityhttps://github.com/NativeScript/android/security
Insightshttps://github.com/NativeScript/android/insights
Sign up for GitHub https://github.com/signup?return_to=%2FNativeScript%2Fandroid%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2FNativeScript%2Fandroid%2Fissues%2Fnew%2Fchoose
dpwhittakerhttps://github.com/dpwhittaker
NativeScript:mainhttps://github.com/NativeScript/android/tree/main
dpwhittaker:fix/arraybuffer-global-ref-leakhttps://github.com/dpwhittaker/nativescript-android/tree/fix/arraybuffer-global-ref-leak
Conversation 2 https://github.com/NativeScript/android/pull/2062
Commits 1 https://github.com/NativeScript/android/pull/2062/commits
Checks 0 https://github.com/NativeScript/android/pull/2062/checks
Files changed https://github.com/NativeScript/android/pull/2062/files
Please reload this pagehttps://github.com/NativeScript/android/pull/2062/files
fix: stop leaking a JNI global ref per ArrayBuffer passed to Java https://github.com/NativeScript/android/pull/2062/files#top
Show all changes 1 commit https://github.com/NativeScript/android/pull/2062/files
4918314 fix: stop leaking a JNI global ref per ArrayBuffer passed to Java dpwhittaker Oct 4, 2026 https://github.com/NativeScript/android/pull/2062/commits/4918314444c3f336e19c837a474a0c6953e63b9f
Clear filters https://github.com/NativeScript/android/pull/2062/files
Please reload this pagehttps://github.com/NativeScript/android/pull/2062/files
Please reload this pagehttps://github.com/NativeScript/android/pull/2062/files
byte-buffer-test.js https://github.com/NativeScript/android/pull/2062/files#diff-48e31116657b36c5fb82bcbdef05b10acc4c9964e47552f37fb6009e3b3df374
JsArgConverter.cpp https://github.com/NativeScript/android/pull/2062/files#diff-9b41f905739990783e7f543f4c38aab34593873cf03762c959d6c3c7b6e991b7
JsArgToArrayConverter.cpp https://github.com/NativeScript/android/pull/2062/files#diff-2893b81a974ae0a84357d112dd872c8c7f3f3c74342ed15f25596e8f928e6ebf
test-app/app/src/main/assets/app/tests/byte-buffer-test.jshttps://github.com/NativeScript/android/pull/2062/files#diff-48e31116657b36c5fb82bcbdef05b10acc4c9964e47552f37fb6009e3b3df374
View file https://github.com/dpwhittaker/nativescript-android/blob/4918314444c3f336e19c837a474a0c6953e63b9f/test-app/app/src/main/assets/app/tests/byte-buffer-test.js
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2062/{{ revealButtonHref }}
https://github.com/NativeScript/android/pull/2062/files#diff-48e31116657b36c5fb82bcbdef05b10acc4c9964e47552f37fb6009e3b3df374
test-app/runtime/src/main/cpp/JsArgConverter.cpphttps://github.com/NativeScript/android/pull/2062/files#diff-9b41f905739990783e7f543f4c38aab34593873cf03762c959d6c3c7b6e991b7
View file https://github.com/dpwhittaker/nativescript-android/blob/4918314444c3f336e19c837a474a0c6953e63b9f/test-app/runtime/src/main/cpp/JsArgConverter.cpp
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2062/{{ revealButtonHref }}
https://github.com/NativeScript/android/pull/2062/files#diff-9b41f905739990783e7f543f4c38aab34593873cf03762c959d6c3c7b6e991b7
https://github.com/NativeScript/android/pull/2062/files#diff-9b41f905739990783e7f543f4c38aab34593873cf03762c959d6c3c7b6e991b7
test-app/runtime/src/main/cpp/JsArgToArrayConverter.cpphttps://github.com/NativeScript/android/pull/2062/files#diff-2893b81a974ae0a84357d112dd872c8c7f3f3c74342ed15f25596e8f928e6ebf
View file https://github.com/dpwhittaker/nativescript-android/blob/4918314444c3f336e19c837a474a0c6953e63b9f/test-app/runtime/src/main/cpp/JsArgToArrayConverter.cpp
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2062/{{ revealButtonHref }}
https://github.com/NativeScript/android/pull/2062/files#diff-2893b81a974ae0a84357d112dd872c8c7f3f3c74342ed15f25596e8f928e6ebf
https://github.com/NativeScript/android/pull/2062/files#diff-2893b81a974ae0a84357d112dd872c8c7f3f3c74342ed15f25596e8f928e6ebf
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.