René's URL Explorer Experiment


Title: fix: release ObjectManager's JS handles and JNI weak refs at teardown by edusperoni · Pull Request #2008 · NativeScript/android · GitHub

Open Graph Title: fix: release ObjectManager's JS handles and JNI weak refs at teardown by edusperoni · Pull Request #2008 · NativeScript/android

X Title: fix: release ObjectManager's JS handles and JNI weak refs at teardown by edusperoni · Pull Request #2008 · NativeScript/android

Description: Stacked on #2006 — it depends on that PR's DestroyRuntime teardown ordering. Review #2006 first; the diff here is 4 files. Problem ObjectManager has no destructor. delete m_objectManager runs the implicit one, which destroys the containers and abandons everything they point at. The expensive part: JNI weak global refs m_cache (an LRUCache, capacity 1000) holds one JNI weak global ref per entry. LRUCache runs its evict callback only under capacity pressure or explicit invalidation — never at destruction, because it had no destructor either. So a worker that touched Java objects abandons its entire cache when it dies. ART's weak-global table is bounded (~51200 entries), so this is not merely a leak: enough worker cycles exhaust it and ART aborts with weak global reference table overflow. The JS side Every linked object owns a Persistent, a JSInstanceInfo and an ObjectWeakCallbackState, freed only from the GC finalizer — and V8 does not run weak callbacks when an isolate is disposed. It is worse than "some survive". In the default none marking mode (AppConfig.java), JSObjectFinalizer re-arms SetWeak whenever the Java counterpart is still alive, so those wrappers are deliberately retained and are therefore all still live at teardown. Fix Split across the two windows teardown actually has: Phase Runs in Isolate JNI Does ReleaseAllRegistered() DestroyRuntime alive, locked alive clears each wrapper's JsInfo internal field before freeing the JSInstanceInfo it points at, resets + deletes the Persistent, releases m_poJsWrapperFunc ~ObjectManager ~Runtime disposed alive, attached clears the LRU cache, which now evicts through the callback; touches no v8 handle That ordering is not incidental: Persistent::Reset() after Isolate::Dispose() writes into a freed handle table, so the V8 phase must be in DestroyRuntime. The JNI eviction must happen before ~Runtime drops the com.tns.Runtime global ref (added in #2006), because ObjectManager calls Java through that same object. Supporting changes m_idToObject now maps to ObjectWeakCallbackState* rather than the bare Persistent*. The state was created and handed to SetWeak but stored nowhere, so teardown had no way to reach it — or the JSInstanceInfo — at all. 7 use sites. LRUCache::clear() — evicts every entry through the callback. Without it the cache cannot release what it owns. ReleaseJSInstance now frees the callback state, which it never did (a smaller pre-existing leak on the same path). Testing Full suite green, and the crash-loop harness from #2006 (SIGSEGV handler temporarily disabled so faults are fatal and tombstoned, not part of this PR) — result posted below once the 20-run loop finishes. Notes for review The full-marking paths (ReleaseRegularObjects, MakeRegularObjectsWeak) are untouched. Worth knowing: three of ObjectManager's declared methods — MakeRegularObjectsWeak, MakeImplObjectsWeak, CheckWeakObjectsAreAlive — have no definition anywhere in the tree and are called from nowhere. They are not part of this fix, but they are why "something else already drains these maps" is not true. Remaining lifetime work is tracked in #2010 — notably NativeScriptException::m_javascriptException, whose raw pointer is handed to Java as a jlong, so fixing it changes a cross-language ownership contract. (~MetadataNodeCache was completed in #2006, where that destructor lives.) Summary by CodeRabbit Bug Fixes Improved runtime cleanup during shutdown to help prevent stale JavaScript-to-native object references. Ensured cached resources are fully cleared, including invoking configured cleanup callbacks for cached values. Strengthened object and wrapper release handling while the runtime is shutting down. Reduced the risk of lingering resources and inconsistent state after runtime teardown.

Open Graph Description: Stacked on #2006 — it depends on that PR's DestroyRuntime teardown ordering. Review #2006 first; the diff here is 4 files. Problem ObjectManager has no destructor. delete m_objectManager runs ...

X Description: Stacked on #2006 — it depends on that PR's DestroyRuntime teardown ordering. Review #2006 first; the diff here is 4 files. Problem ObjectManager has no destructor. delete m_objectManager r...

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

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:62bbed2c-8216-738c-0529-fde86a663d80
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idA25A:2C4BED:192C432:1FF9998:6B014527
html-safe-nonce407ec84ff3e3de499e9344a81566846bd5b1b28015bf30d27966e0d4a271a790
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMjVBOjJDNEJFRDoxOTJDNDMyOjFGRjk5OTg6NkIwMTQ1MjciLCJ2aXNpdG9yX2lkIjoiMTQ5MjcwOTgzODIwNjA5MjU4MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac73abe1fde209b788f1e5b227ae641d22aa52c0b32b0899dd9f61f970e8213b24
hovercard-subject-tagpull_request:4283647758
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/2008/files
twitter:imagehttps://avatars.githubusercontent.com/u/4061767?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/4061767?s=400&v=4
og:image:altStacked on #2006 — it depends on that PR's DestroyRuntime teardown ordering. Review #2006 first; the diff here is 4 files. Problem ObjectManager has no destructor. delete m_objectManager runs ...
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/2008/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FNativeScript%2Fandroid%2Fpull%2F2008%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%2F2008%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/2008/files
Reloadhttps://github.com/NativeScript/android/pull/2008/files
Reloadhttps://github.com/NativeScript/android/pull/2008/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
edusperonihttps://github.com/edusperoni
mainhttps://github.com/NativeScript/android/tree/main
fix/objectmanager-teardownhttps://github.com/NativeScript/android/tree/fix/objectmanager-teardown
Conversation 3 https://github.com/NativeScript/android/pull/2008
Commits 2 https://github.com/NativeScript/android/pull/2008/commits
Checks 7 https://github.com/NativeScript/android/pull/2008/checks
Files changed https://github.com/NativeScript/android/pull/2008/files
Please reload this pagehttps://github.com/NativeScript/android/pull/2008/files
fix: release ObjectManager's JS handles and JNI weak refs at teardown https://github.com/NativeScript/android/pull/2008/files#top
Show all changes 2 commits https://github.com/NativeScript/android/pull/2008/files
4ac3ce7 fix: release ObjectManager's JS handles and JNI weak refs at teardown edusperoni Aug 14, 2026 https://github.com/NativeScript/android/pull/2008/commits/4ac3ce773e56d6c7db2e27de834599f01d33a862
a62f4df fix: keep the ObjectManager registration consistent when the link is … edusperoni Aug 14, 2026 https://github.com/NativeScript/android/pull/2008/commits/a62f4df8d029cab8cecf747e5b9d6ff4649082e0
Clear filters https://github.com/NativeScript/android/pull/2008/files
Please reload this pagehttps://github.com/NativeScript/android/pull/2008/files
Please reload this pagehttps://github.com/NativeScript/android/pull/2008/files
LRUCache.h https://github.com/NativeScript/android/pull/2008/files#diff-0a9f9505289be20c65f9e67b1540900685b18492089185e6e1b06e829ecfc46f
ObjectManager.cpp https://github.com/NativeScript/android/pull/2008/files#diff-0591ab8dc271af7e8ef11fabf0642e44b932f38003bd07a3696de149a02b2c9b
ObjectManager.h https://github.com/NativeScript/android/pull/2008/files#diff-d491cf1566875df8740b3e9d732ac891286a776623aad17b249b36781ac7047d
Runtime.cpp https://github.com/NativeScript/android/pull/2008/files#diff-b9490640f5d26f7cd6b9a176a2142b8e985a6aac9e2d64287de37fc694e80cc3
test-app/runtime/src/main/cpp/LRUCache.hhttps://github.com/NativeScript/android/pull/2008/files#diff-0a9f9505289be20c65f9e67b1540900685b18492089185e6e1b06e829ecfc46f
View file https://github.com/NativeScript/android/blob/a62f4df8d029cab8cecf747e5b9d6ff4649082e0/test-app/runtime/src/main/cpp/LRUCache.h
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2008/{{ revealButtonHref }}
https://github.com/NativeScript/android/pull/2008/files#diff-0a9f9505289be20c65f9e67b1540900685b18492089185e6e1b06e829ecfc46f
https://github.com/NativeScript/android/pull/2008/files#diff-0a9f9505289be20c65f9e67b1540900685b18492089185e6e1b06e829ecfc46f
test-app/runtime/src/main/cpp/ObjectManager.cpphttps://github.com/NativeScript/android/pull/2008/files#diff-0591ab8dc271af7e8ef11fabf0642e44b932f38003bd07a3696de149a02b2c9b
View file https://github.com/NativeScript/android/blob/a62f4df8d029cab8cecf747e5b9d6ff4649082e0/test-app/runtime/src/main/cpp/ObjectManager.cpp
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2008/{{ revealButtonHref }}
https://github.com/NativeScript/android/pull/2008/files#diff-0591ab8dc271af7e8ef11fabf0642e44b932f38003bd07a3696de149a02b2c9b
https://github.com/NativeScript/android/pull/2008/files#diff-0591ab8dc271af7e8ef11fabf0642e44b932f38003bd07a3696de149a02b2c9b
https://github.com/NativeScript/android/pull/2008/files#diff-0591ab8dc271af7e8ef11fabf0642e44b932f38003bd07a3696de149a02b2c9b
https://github.com/NativeScript/android/pull/2008/files#diff-0591ab8dc271af7e8ef11fabf0642e44b932f38003bd07a3696de149a02b2c9b
https://github.com/NativeScript/android/pull/2008/files#diff-0591ab8dc271af7e8ef11fabf0642e44b932f38003bd07a3696de149a02b2c9b
https://github.com/NativeScript/android/pull/2008/files#diff-0591ab8dc271af7e8ef11fabf0642e44b932f38003bd07a3696de149a02b2c9b
https://github.com/NativeScript/android/pull/2008/files#diff-0591ab8dc271af7e8ef11fabf0642e44b932f38003bd07a3696de149a02b2c9b
Please reload this pagehttps://github.com/NativeScript/android/pull/2008/files
https://github.com/NativeScript/android/pull/2008/files#diff-0591ab8dc271af7e8ef11fabf0642e44b932f38003bd07a3696de149a02b2c9b
https://github.com/NativeScript/android/pull/2008/files#diff-0591ab8dc271af7e8ef11fabf0642e44b932f38003bd07a3696de149a02b2c9b
https://github.com/NativeScript/android/pull/2008/files#diff-0591ab8dc271af7e8ef11fabf0642e44b932f38003bd07a3696de149a02b2c9b
https://github.com/NativeScript/android/pull/2008/files#diff-0591ab8dc271af7e8ef11fabf0642e44b932f38003bd07a3696de149a02b2c9b
test-app/runtime/src/main/cpp/ObjectManager.hhttps://github.com/NativeScript/android/pull/2008/files#diff-d491cf1566875df8740b3e9d732ac891286a776623aad17b249b36781ac7047d
View file https://github.com/NativeScript/android/blob/a62f4df8d029cab8cecf747e5b9d6ff4649082e0/test-app/runtime/src/main/cpp/ObjectManager.h
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2008/{{ revealButtonHref }}
https://github.com/NativeScript/android/pull/2008/files#diff-d491cf1566875df8740b3e9d732ac891286a776623aad17b249b36781ac7047d
https://github.com/NativeScript/android/pull/2008/files#diff-d491cf1566875df8740b3e9d732ac891286a776623aad17b249b36781ac7047d
https://github.com/NativeScript/android/pull/2008/files#diff-d491cf1566875df8740b3e9d732ac891286a776623aad17b249b36781ac7047d
https://github.com/NativeScript/android/pull/2008/files#diff-d491cf1566875df8740b3e9d732ac891286a776623aad17b249b36781ac7047d
https://github.com/NativeScript/android/pull/2008/files#diff-d491cf1566875df8740b3e9d732ac891286a776623aad17b249b36781ac7047d
https://github.com/NativeScript/android/pull/2008/files#diff-d491cf1566875df8740b3e9d732ac891286a776623aad17b249b36781ac7047d
test-app/runtime/src/main/cpp/Runtime.cpphttps://github.com/NativeScript/android/pull/2008/files#diff-b9490640f5d26f7cd6b9a176a2142b8e985a6aac9e2d64287de37fc694e80cc3
View file https://github.com/NativeScript/android/blob/a62f4df8d029cab8cecf747e5b9d6ff4649082e0/test-app/runtime/src/main/cpp/Runtime.cpp
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2008/{{ revealButtonHref }}
https://github.com/NativeScript/android/pull/2008/files#diff-b9490640f5d26f7cd6b9a176a2142b8e985a6aac9e2d64287de37fc694e80cc3
https://github.com/NativeScript/android/pull/2008/files#diff-b9490640f5d26f7cd6b9a176a2142b8e985a6aac9e2d64287de37fc694e80cc3
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.