René's URL Explorer Experiment


Title: Runtime lifetime: deferred leaks, cross-isolate sharing, and startup robustness · Issue #2010 · NativeScript/android · GitHub

Open Graph Title: Runtime lifetime: deferred leaks, cross-isolate sharing, and startup robustness · Issue #2010 · NativeScript/android

X Title: Runtime lifetime: deferred leaks, cross-isolate sharing, and startup robustness · Issue #2010 · NativeScript/android

Description: Tracking issue for lifetime problems found while fixing the intermittent worker SIGSEGV (#2006) and the ObjectManager teardown (#2008), and deliberately not fixed there. Each was verified by reading the code; none is speculative. Line nu...

Open Graph Description: Tracking issue for lifetime problems found while fixing the intermittent worker SIGSEGV (#2006) and the ObjectManager teardown (#2008), and deliberately not fixed there. Each was verified by readin...

X Description: Tracking issue for lifetime problems found while fixing the intermittent worker SIGSEGV (#2006) and the ObjectManager teardown (#2008), and deliberately not fixed there. Each was verified by readin...

Opengraph URL: https://github.com/NativeScript/android/issues/2010

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Runtime lifetime: deferred leaks, cross-isolate sharing, and startup robustness","articleBody":"Tracking issue for lifetime problems found while fixing the intermittent worker `SIGSEGV` (#2006) and the `ObjectManager` teardown (#2008), and deliberately **not** fixed there. Each was verified by reading the code; none is speculative. Line numbers are as of `fix/objectmanager-teardown`.\n\nTwo facts underpin most of these, and are worth stating once:\n\n- **V8 does not run weak callbacks when an isolate is disposed.** Anything that frees itself only from a GC finalizer leaks every instance that is still alive when a runtime goes away — and workers make that happen constantly.\n- **`v8::Persistent` and `v8::Global` differ at destruction.** `Persistent` uses `NonCopyablePersistentTraits` (`kResetInDestructor == false`), so `~Persistent` never calls into V8 and `delete po` after `Isolate::Dispose()` is safe. `Global` always resets, so destroying one after disposal writes into a freed handle table. That single difference decides which teardown window each fix belongs in.\n\nThe three windows, from `WorkerWrapper.cpp:461-503`:\n\n| Window | Isolate | JNI | Use for |\n| --- | --- | --- | --- |\n| `Runtime::DestroyRuntime()` | alive, locked | alive | anything touching `v8::Global` / `Persistent::Reset` / JS objects |\n| `~Runtime()` | **disposed** | alive, attached | JNI ref release, `delete` of `Persistent\u003cT>*` |\n| after `DetachCurrentThread` | gone | **detached** | nothing |\n\n---\n\n## Startup robustness\n\n- [ ] **Main-runtime initialization and election are not serialized.** `initRuntime` (`Runtime.java:572-576`) calls the `synchronized (Runtime.currentRuntime)` constructor and *then* `runtime.init()` — and `init()`, which reaches `initNativeScript` → `PrepareV8Runtime`, is **outside** that block. So the `s_mainThreadInitialized` check-then-act is not protected: two concurrent bootstraps could both run `InitializeV8()`, both elect a main runtime, and overwrite `Runtime::platform` / `s_mainEventLoop`. Unreachable today only by ordering — workers are always created from an already-initialized main runtime — so it becomes reachable with concurrent bootstrap (embedding host, `reloadApplication`). Wants `std::call_once` around the whole init-and-elect sequence plus a separate ready signal for workers. (Raised in review of #2006.)\n\n- [ ] **Partial native initialization is never unwound.** If `PrepareV8Runtime` throws after `Isolate::New()`, the isolate is already in `s_isolate2RuntimesCache` but the Java-side rollback only unwinds Java state, leaving the isolate and the half-built `Runtime` allocated. The fix should reuse the two-window teardown above rather than add a third cleanup path. (Raised in review of #2006.)\n\n## Leaks still outstanding\n\n- [ ] **`NativeScriptException::m_javascriptException`** (`NativeScriptException.h:166`, allocated `:48-49`) — a `Persistent\u003cValue>*` holding a **strong** handle to the JS `Error` and its captured stack. **This is the only one that grows within a live runtime**, including the long-lived main one, once per `NativeScriptException(TryCatch&)` that does not round-trip through Java. Not a simple destructor fix: the raw pointer is deliberately handed to Java as a `jlong` (`NativeScriptException.cpp:152` → `NativeScriptException.java:6`) and reclaimed at `:803-810`, so a naive destructor double-frees. Fixing it means changing that cross-language ownership contract.\n\n- [ ] **`ModuleInternal::m_loadedModules`** (`ModuleInternal.h:101`) — one `Persistent\u003cObject>` per loaded module (`ModuleInternal.cpp:376`, `:570`), never freed; `~ModuleInternal` frees its three siblings but not this one. Small (bounded by module count). **Trap:** `TempModule` inserts the same pointer under two keys (`m_modulePath` and `m_cacheKey`), so a naive delete-every-value loop double-frees — dedup by pointer.\n\n- [ ] **`CtorCacheData::instanceMethodCallbacks`** — the `MethodCallbackData*` elements (`MetadataNode.cpp:680`, `:706`, `:856`, `:899`, `:2217`), each carrying a `vector\u003cMetadataEntry>` (~200-500 B). #2008 frees the two `Persistent`s in those caches but deliberately leaves these: they may be shared across entries, so it needs an ownership analysis first.\n\n- [ ] **PODs attached to V8 objects with no finalizer at all** — `TypeMetadata` (`MetadataNode.cpp:1104`, `:1776`), `FieldCallbackData` (`:757`, `:874`, `:922`), `PropertyCallbackData` (`:787`), `ExtendedClassCallbackData` (`:1757`, which also holds a **strong** `Persistent\u003cObject>` pinning the whole JS implementation object). These leak on **every GC**, not only at teardown. Note `MetadataNode.cpp` contains no `delete` at all. They want an owner on the per-runtime `MetadataNodeCache`.\n\n## Cross-isolate sharing (not leaks — the same failure class as #2006)\n\n- [ ] **`HMRSupport`'s three global maps** (`HMRSupport.cpp:22-24`) — `g_hotData`, `g_hotAccept`, `g_hotDispose`, path-keyed, process-wide, unsynchronized, never cleaned, reached from `InitializeImportMetaObject` for every ES module. Same shape as the ES-module registry and the same `.mjs` gating, so low probability today. Should move to `RuntimeState`.\n\n- [ ] **`MetadataNode`'s three static node caches** (`MetadataNode.cpp:2315-2317`) — `s_name2NodeCache`, `s_name2TreeNodeCache`, `s_treeNode2NodeCache`, still unguarded and mutated from any runtime's thread (`GetOrCreate` inserts at `:144-151`, on **every** JS-wrapper creation via `ObjectManager::CreateJSWrapperHelper`). Not a leak — the nodes are bounded — but it is the same container-corruption shape as the `Console` crash, on a hotter path.\n\n- [ ] **The metadata tree and `MetadataReader`'s buffers.** Bigger than the caches: `m_valueData`/`m_valueLength` (`MetadataReader.cpp:320-323`) is a bump allocator, and `m_v.push_back` (`:219`, `:264`, `:328`) reallocates a vector that `GetNodeById` (`:96-98`) indexes **with no bounds check** — a realloc under a concurrent read is a use-after-free. Only reached for types absent from the static metadata, so rare but destructive.\n\n  **This one cannot take a coarse lock.** `GetOrCreateTreeNodeByName` mutates those buffers *while calling back into Java* (`CallbackHandlers::GetTypeMetadata` → `Runtime.getTypeMetadata` → `Class.forName`). A function-scope mutex would be held across ART class loading and, on the `.extend()` path, dex generation — and could invert against the process-wide monitor in `Runtime.java:229` and the `r.wait()` cross-thread `callJSMethod` path. It needs a narrow recursive mutex guarding state access only, with the ordering rule: the only permitted successor is `Runtime::s_runtimeCacheMutex`; never hold it across a JNI call that can re-enter JS.\n\n## Cosmetic\n\n- [ ] **ODR violation in `IsolateDisposer.h:24-25`** — `isolateBoundObjects_` and `isolateBoundObjectsMutex_` are defined at namespace scope *in a header* included by three TUs. `nm` shows the same mangled symbol as a strong definition in each object file; the link collapses them, so it is benign in practice and the map genuinely is shared as intended, but it should be `inline` (C++17).\n\n---\n\n### Already handled elsewhere, recorded so they are not re-investigated\n\n- `g_moduleRegistry` — the process-wide, unsynchronized, path-keyed ES-module registry is reworked into per-isolate state in #1965.\n- `SIG_handler` throwing from a signal handler (which suppressed tombstones and is why all of this read as flaky tests for weeks) — removed in #2007.\n\n### Verified **not** leaks\n\n`Timers`, `BuiltinLoader`, `NsBuiltinModules`, `Events`/`ErrorEvents`/`PromiseRejectionTracker`, `WorkerInspectorClient`, the `napi` layer, `DirectBuffer`, and `WeakRef` all release correctly, mostly via `registerIsolateBoundObject` or explicit resets in `DestroyRuntime` before disposal. `JsV8InspectorClient::Domains` looked like cross-isolate corruption but is not: only the main isolate ever populates it (`__registerDomainDispatcher` is installed by `registerModules()` alone, and `WorkerInspectorClient` never installs it). Cached `jclass` statics look like dangling local refs but come from `JEnv::FindClass`, which returns process-wide **global** refs.\n","author":{"url":"https://github.com/edusperoni","@type":"Person","name":"edusperoni"},"datePublished":"2026-08-14T22:47:42Z","url":"https://github.com/NativeScript/android/issues/2010"}

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/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:2098f688-4e37-24bd-f6c2-58ad8548ba09
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE53A:1F44:101685B:150F33C:6B013377
html-safe-nonce111eb5515d32a5eef86edc94e1725bd937b8f8810a09729741fdd514625bcec6
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNTNBOjFGNDQ6MTAxNjg1QjoxNTBGMzNDOjZCMDEzMzc3IiwidmlzaXRvcl9pZCI6Ijc5Njc4MzA4MzMxOTUyMDEzOTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacab5a8d0ef36622ef87fa366d8b4692b8bed482abeea3652e0659ae75417670a7
hovercard-subject-tagissue:5156241941
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/NativeScript/android/2010/issue_layout
twitter:imagehttps://opengraph.githubassets.com/ac6e0ba111f1764a89ee47f07d0f26755c50c400d776426d4bbc855f9b0ee189/NativeScript/android/issues/2010
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/ac6e0ba111f1764a89ee47f07d0f26755c50c400d776426d4bbc855f9b0ee189/NativeScript/android/issues/2010
og:image:altTracking issue for lifetime problems found while fixing the intermittent worker SIGSEGV (#2006) and the ObjectManager teardown (#2008), and deliberately not fixed there. Each was verified by readin...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameedusperoni
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
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
disable-turbofalse
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
react-app-nameissues

Links:

Skip to contenthttps://github.com/NativeScript/android/issues/2010#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FNativeScript%2Fandroid%2Fissues%2F2010
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%2Fissues%2F2010
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=NativeScript%2Fandroid
Reloadhttps://github.com/NativeScript/android/issues/2010
Reloadhttps://github.com/NativeScript/android/issues/2010
Reloadhttps://github.com/NativeScript/android/issues/2010
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
https://github.com/NativeScript/android
New issuehttps://github.com/login?return_to=https://github.com/NativeScript/android/issues/2010
New issuehttps://github.com/login?return_to=https://github.com/NativeScript/android/issues/2010
#2013https://github.com/NativeScript/android/pull/2013
Runtime lifetime: deferred leaks, cross-isolate sharing, and startup robustnesshttps://github.com/NativeScript/android/issues/2010#top
#2013https://github.com/NativeScript/android/pull/2013
https://github.com/edusperoni
edusperonihttps://github.com/edusperoni
on Aug 14, 2026https://github.com/NativeScript/android/issues/2010#issue-5156241941
#2006https://github.com/NativeScript/android/pull/2006
#2008https://github.com/NativeScript/android/pull/2008
fix: isolate/runtime lifetime — worker startup race, teardown use-after-free, and leaks #2006https://github.com/NativeScript/android/pull/2006
fix: isolate/runtime lifetime — worker startup race, teardown use-after-free, and leaks #2006https://github.com/NativeScript/android/pull/2006
fix: release ObjectManager's JS handles and JNI weak refs at teardown #2008https://github.com/NativeScript/android/pull/2008
#2006https://github.com/NativeScript/android/pull/2006
feat: ESM loader overhaul — Web/Node parity, ns:module dev surface, HTTP module loader #1965https://github.com/NativeScript/android/pull/1965
fix: restore native tombstones and record runtime crash breadcrumbs #2007https://github.com/NativeScript/android/pull/2007
edusperonihttps://github.com/edusperoni
completedhttps://github.com/NativeScript/android/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#2013https://github.com/NativeScript/android/pull/2013
on Aug 15, 2026https://github.com/NativeScript/android/issues/2010#event-29504788820
Sign up for freehttps://github.com/signup?return_to=https://github.com/NativeScript/android/issues/2010
Sign in to commenthttps://github.com/login?return_to=https://github.com/NativeScript/android/issues/2010
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.