Reading a computed atom without subscribing can prevent garbage collection
Los mantenedores suelen responder en 1 día
@Sheraff ya está trabajando en esto.
Desde el 28/9/2026.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 58/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- react, typescript
- Área
- frontend, performance
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 900
- Forks
- 116
- Merge medio
- 1 d 21 h
- PR fusionados (30 d)
- 7
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de TanStack/store
-
useSelector wraps selected objects in $state, causing state_proxy_equality_mismatch and defeating identity comparisonPosiblemente ocupada @IdrisCelik la tomó hace 24 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
`useSelector` triggers `state_proxy_equality_mismatch` on every store update in svelte-storePosiblemente ocupada @seongwon030 la tomó hace 138 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
TanStack/store#322 · 2 comentarios · 5 reacciones ·
Los mantenedores suelen responder en 1 día
-
Missing atom docsPosiblemente ocupada @looooown2006 la tomó hace 152 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
TanStack/store#299 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Type error in `useStore` when upgrading from 1.28.0 to 1.28.4Quizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 52/100
TanStack/store#323 · 2 comentarios · 1 reacción ·
Los mantenedores suelen responder en 1 día
Todos los issues de TanStack/store
Issues similares
-
refactor
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
tomnewport/memprot-topo#55 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
WalletConnect/walletconnect-monorepo#7368 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
BU-Spark/se-chem-apll#47 ·
-
embed: handleTurboSignMessage header comment says the signing page posts to '*' (it never does)Abiertodocumentation
Dificultad 2/5 Menos de una hora Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 Medio día Aptitud para principiantes 70/100
udistrital/paginaweb_root#23 ·