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.

Memory Leak: Mutation + OptimisticResponse makes update function to leak

See original GitHub issue

After executing a mutation with update function and optimisticResponse the update function is hold in memory forever which leaks other referenced objects.

How to reproduce the issue: https://github.com/kamilkisiela/apollo-optimistic-response-pessimistic-memory-leak

npm install
npm run start
  1. Open chrome://inspector
  2. Connect to a process
  3. Click play on first breaking point
  4. On next breaking point, take a snapshot
  5. Look for Foo class
Zrzut ekranu 2020-11-17 o 14 53 35

@benjamn I can confirm that Cache.removeOptimistic is called but Foo is still there

https://github.com/apollographql/apollo-client/blob/291e8bd8ab6c9033be2e50af4df3bf56b5c4da43/src/core/QueryManager.ts#L273

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
benjamncommented, Nov 18, 2020

@kamilkisiela I’ve updated the optimism library so that it no longer holds onto entry.args arrays (see https://github.com/benjamn/optimism/pull/104), so memory leaks related to arguments passed to methods like executeSelectionSet should no longer be possible.

Following your reproduction steps, I no longer see retainment paths for Foo objects with lines like args in Entry @1663111 (or anything above it).

These changes were published in optimism@0.13.1 and can be tested by running either npm i optimism@latest or npm i @apollo/client@3.3.0-rc.2.

It might still be worthwhile to evict/forget Entry objects associated with optimistic updates that have been rolled back, but I’d want to see some evidence that’s still a problem, now that function arguments are no longer retained.

1reaction
smykhailovcommented, Nov 19, 2020

should #7276 be merged into master too? It should minimize amount of potential memory leaks too

Read more comments on GitHub >

github_iconTop Results From Across the Web

Optimistic mutation results - Apollo GraphQL Docs
If our app is wrong (e.g., the GraphQL server returns an unchanged Comment due to an error), the UI will automatically update to...
Read more >
graphql after running mutation if I quickly goback to ...
Even if move to another page during mutating, I want to proceed with the update as it is How can I proceed with...
Read more >
[React +GraphQL] Using refetchQuery causes memory ...
Error code: Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak...
Read more >
Developing a Data Sync Application
Because of this, when mutations that can change query results are performed, the refetchQueries or update options of the mutate method should be...
Read more >
vue/apollo-option
Bug Fixes · apollo components registered twice, fix #1336 (3ad3ab3) · change data init, related to #1350 (b94bdf7) · Make calls of the...
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