Title: [Medium][reactive] Composables create effects/computeds with no disposal path (memory leaks) · Issue #173 · bQuery/bQuery · GitHub
Open Graph Title: [Medium][reactive] Composables create effects/computeds with no disposal path (memory leaks) · Issue #173 · bQuery/bQuery
X Title: [Medium][reactive] Composables create effects/computeds with no disposal path (memory leaks) · Issue #173 · bQuery/bQuery
Description: Severity: 🟡 Medium (memory leaks) Several composables create long-lived reactive primitives with no disposal path, so they (and the timers/subscriptions they hold) leak whenever they are not created inside an active effectScope. Location...
Open Graph Description: Severity: 🟡 Medium (memory leaks) Several composables create long-lived reactive primitives with no disposal path, so they (and the timers/subscriptions they hold) leak whenever they are not create...
X Description: Severity: 🟡 Medium (memory leaks) Several composables create long-lived reactive primitives with no disposal path, so they (and the timers/subscriptions they hold) leak whenever they are not create...
Opengraph URL: https://github.com/bQuery/bQuery/issues/173
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Medium][reactive] Composables create effects/computeds with no disposal path (memory leaks)","articleBody":"## Severity: 🟡 Medium (memory leaks)\n\nSeveral composables create long-lived reactive primitives with **no disposal path**, so they (and the timers/subscriptions they hold) leak whenever they are not created inside an active `effectScope`.\n\n## Locations \u0026 details\n\n### 1. `deferred()` leaks its internal effect\n[`src/concurrency/scheduling.ts:141-161`](../blob/main/src/concurrency/scheduling.ts#L141-L161) — `deferred(source)` creates an `effect(() =\u003e …)` subscribing to `source` and returns only `readonly(mirror)`. There is no returned dispose and no `onScopeDispose` registration. Outside a scope, the effect (plus the scheduled timer/idle callback it manages) stays subscribed to `source` for the source's lifetime.\n\n### 2. `persistedSignal()` persistence effect has no disposer\n[`src/reactive/persisted.ts:63-71`](../blob/main/src/reactive/persisted.ts#L63-L71) — the persistence `effect()` returns no disposer. There is no way to stop persistence; and because `effect()` auto-registers with the ambient `effectScope`, calling `persistedSignal()` inside a scope means `scope.stop()` silently stops persistence while the signal keeps living.\n\n### 3. Unscoped `computed()` retained by a long-lived signal\n[`src/reactive/core.ts:23`](../blob/main/src/reactive/core.ts#L23), [`src/reactive/computed.ts:137-142`](../blob/main/src/reactive/computed.ts#L137-L142) — a `Signal` holds subscribers in a strong `Set`, and `computed()` only auto-disposes when created inside an active `effectScope`. A `computed` created at module/function scope, read once, depending on a long-lived signal, keeps its `markDirty` in the signal's subscriber set forever even after all user references drop.\n\n## Suggested fix\n- `deferred()`: return a `dispose()` (stop the effect + `scheduled.cancel()`), or register cleanup via `onScopeDispose` when a scope is active (mirroring `usePolling`/`suspense`).\n- `persistedSignal()`: isolate the persistence watcher from the ambient scope and/or return a `dispose`.\n- `computed()`: document the must-dispose contract prominently and/or provide auto-cleanup (`FinalizationRegistry`/`WeakRef`-based pruning), or have composables that internally create computeds aggregate their disposal.\n\n---\n_Filed as part of a full-codebase security \u0026 correctness audit._\n","author":{"url":"https://github.com/JosunLP","@type":"Person","name":"JosunLP"},"datePublished":"2026-07-05T17:03:21.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/173/bQuery/issues/173"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ff9ff239-29b3-504f-a1f8-d53cbffc92fe |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 83BA:2C6DF7:517CDD:6F4E39:6A4DCB27 |
| html-safe-nonce | 13266be09a4d5c60973f500e536f0d87fa53c17abdc798720caaeac3f3d38606 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4M0JBOjJDNkRGNzo1MTdDREQ6NkY0RTM5OjZBNERDQjI3IiwidmlzaXRvcl9pZCI6IjY3ODU1NjU4MTU2NTc1ODEzNTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c85d76e765e53abbf4ea41ce7ccb34a78a158d355295e723b0c07c266014ec90 |
| hovercard-subject-tag | issue:4813694816 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/bQuery/bQuery/173/issue_layout |
| twitter:image | https://opengraph.githubassets.com/17cf703fadd4267556c95dc55dd51b22b06dc004ada447bafffadfa0361d904a/bQuery/bQuery/issues/173 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/17cf703fadd4267556c95dc55dd51b22b06dc004ada447bafffadfa0361d904a/bQuery/bQuery/issues/173 |
| og:image:alt | Severity: 🟡 Medium (memory leaks) Several composables create long-lived reactive primitives with no disposal path, so they (and the timers/subscriptions they hold) leak whenever they are not create... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JosunLP |
| hostname | github.com |
| expected-hostname | github.com |
| None | 06b8a6144231bf3a234f1c2e9993861e07ce98a905912b114aa386c2d7e84b33 |
| turbo-cache-control | no-preview |
| go-import | github.com/bQuery/bQuery git https://github.com/bQuery/bQuery.git |
| octolytics-dimension-user_id | 256381806 |
| octolytics-dimension-user_login | bQuery |
| octolytics-dimension-repository_id | 1139284244 |
| octolytics-dimension-repository_nwo | bQuery/bQuery |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1139284244 |
| octolytics-dimension-repository_network_root_nwo | bQuery/bQuery |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 1d344bdb7547fe6bca17a59bb2b8aac3dc9532a0 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width