AC3: Memory leak in `watchQuery` retains `context` object in memory even after `unsubscribe`
See original GitHub issueIntended outcome:
Object passed as context
to watchQuery
method should be released when unsubscribe
is called, instead of being retrained in memory.
I’m opening this because this seems like another symptom of a related issue, but with a testable reproduction, and including the heap snapshots files.
I believe this is very related to what @Torsten85 posted here: https://github.com/apollographql/apollo-client/issues/6985#issuecomment-701240849
Actual outcome:
context
object are retained in memory by AC3:
How to reproduce the issue:
Use watchQuery
with context
set. Apollo keeps reference to that object even if query has done, and unsubscribe
has been called (and all references has been destructed).
You can find a complete reproduction (as a Jest test + instructions) here: https://github.com/dotansimha/apollo-very-pessimism
Versions
>=3
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:6 (6 by maintainers)
Top GitHub Comments
Thanks to @dotansimha’s reproduction and @kamilkisiela’s proposed solution, I’m confident this leak is fixed in
@apollo/client@3.2.4
and@apollo/client@3.3.0-beta.12
. Thanks a ton!@dotansimha As a side note, the weak reference approach you used in your reproduction (using
weak-napi
) is 🤯 —definitely using that the next time I need to write a memory leak regression test that runs in Node!