question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AC3: Memory leak in `watchQuery` retains `context` object in memory even after `unsubscribe`

See original GitHub issue

Intended 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: image

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:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
benjamncommented, Oct 13, 2020

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!

3reactions
benjamncommented, Oct 13, 2020

@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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Find, Fix, and Avoid Memory Leaks in C# .NET: 8 Best Practices
The first core cause is when you have objects that are still referenced but are effectually unused. Since they are referenced, the garbage ......
Read more >
@apollo/client | Yarn - Package Manager
Apollo Client is a fully-featured caching GraphQL client with integrations for React, Angular, and more. It allows you to easily build UI components...
Read more >
apollo-cache-inmemory - Awesome JS
Preserve previousData even when different query or client provided to useQuery ... objects that will be retained in memory (to speed up repeated...
Read more >
https://raw.githubusercontent.com/bendenoz/apollo-...
<br/> [@benjamn](https://github.com/benjamn) in [#9672](https://github.com/apollographql/apollo-client/pull/9672) - Test that `useQuery` queries with `skip: ...
Read more >
Fixing memory leaks in web applications | Read the Tea Leaves
Update: I've written a tool to automate many of the steps described in this post. Part of the bargain we struck when we...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found