Reading a computed atom without subscribing can prevent garbage collection
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 58/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- react, typescript
- 領域
- frontend, performance
調査の方向性
Start with the dependency-tracking logic in atom.ts and run the supplied repro.mjs with Node's --expose-gc flag. Trace how a computed atom read by get() is connected to its source without a subscription. Done means dropped, never-subscribed computed atoms can be collected while the source remains in use, with the reported behavior covered by a regression test.
索引モデルが issue の本文から書いたものです。
説明
A computed atom can stay in memory after the application has finished using it. Reading it once with .get() is enough: its source keeps a reference to it, even if nothing ever subscribes to it.
This matters in React because a component can read an atom during render, then suspend before React subscribes. If that render is discarded, there is no subscription to clean up. Repeated abandoned renders can accumulate unused atoms and anything their getters capture.
Reproduction: @tanstack/[email protected], Node 24.8.0, macOS. Save as repro.mjs and run node --expose-gc repro.mjs.
import { createAtom } from '@tanstack/store'
const source = createAtom(0)
function createAndDiscard() {
const derived = createAtom(() => source.get() + 1)
derived.get() // Read once; never subscribe.
return new WeakRef(derived) // Observe it without keeping it alive.
}
const refs = Array.from({ length: 100 }, createAndDiscard)
// Give garbage collection several chances to release the unused atoms.
for (let i = 0; i < 10; i++) {
await new Promise(resolve => setTimeout(resolve, 0))
global.gc()
}
const remaining = refs.filter(ref => ref.deref() !== undefined).length
console.log(remaining) // Expected: 0. Actual: 100.
console.log(source.get()) // The source is still in use.
Removing derived.get() makes all 100 atoms collectible. Calling derived.subscribe(() => {}).unsubscribe() after the read also allows all 100 to be collected.
The cause appears to be the dependency tracking in atom.ts: reading the computed atom connects it to its source. Unsubscribing removes that connection, but an atom that was never subscribed has no corresponding cleanup.
Expected: once the application drops a computed atom, its source should not keep it alive solely because it was read earlier.
AI disclosure: This report was investigated, reproduced, and written by OpenAI Codex (AI), and filed at the user's request.
- 主要言語
- TypeScript
- スター
- 900
- フォーク
- 116
- 平均マージ
- 2日 2時間
- マージ済み PR(30日)
- 6
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
TanStack/store のほかの issue
-
useSelector wraps selected objects in $state, causing state_proxy_equality_mismatch and defeating identity comparison対応中かも @IdrisCelik が 22 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
`useSelector` triggers `state_proxy_equality_mismatch` on every store update in svelte-store対応中かも @seongwon030 が 136 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
TanStack/store#322 · コメント 2 件 · リアクション 5 件 ·
メンテナーはふだん 1 日以内に返信
-
Missing atom docs対応中かも @looooown2006 が 150 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
TanStack/store#299 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
Type error in `useStore` when upgrading from 1.28.0 to 1.28.4再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 52/100
TanStack/store#323 · コメント 2 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
perf(core): getComments() runs the approved count and the comment list as two sequential queriesオープンarea/core bot:bug bot:working
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
emdash-cms/emdash#3905 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
lingdojo/kana-dojo#31728 · コメント 1 件 · リアクション 5 件 ·
メンテナーはふだん 1 日以内に返信
-
selective-claw: freshTailTurns=0 keeps ALL turns verbatim and summarizes none (slice(-0) === slice(0))対応中かも @zjncs が今日担当しました。 オープンcomponent:tokenless
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
agentic-os-org/ANOLISA#6112 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
rjsf-team/react-jsonschema-form#5439 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信