Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Leak: Mutation + OptimisticResponse makes update function to leak #7339

Closed
kamilkisiela opened this issue Nov 17, 2020 · 5 comments
Closed
Assignees

Comments

@kamilkisiela
Copy link
Contributor

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

self.cache.removeOptimistic(mutationId);

@kamilkisiela
Copy link
Contributor Author

kamilkisiela commented Nov 17, 2020

I think that

private executeSelectionSet: OptimisticWrapperFunction<
[ExecSelectionSetOptions], // Actual arguments tuple type.
ExecResult, // Actual return type.
// Arguments type after keyArgs translation.
[SelectionSetNode, StoreObject | Reference, ReadMergeModifyContext]
> = wrap(options => this.execSelectionSetImpl(options), {

holds a reference forever because it has no cleanup logic.

I think it's exactly the same issue we had #7086

@benjamn benjamn self-assigned this Nov 17, 2020
@benjamn
Copy link
Member

benjamn commented Nov 18, 2020

@kamilkisiela I've updated the optimism library so that it no longer holds onto entry.args arrays (see benjamn/optimism#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.

@kamilkisiela
Copy link
Contributor Author

Thanks, we're going to test it soon

@smykhailov
Copy link

smykhailov commented Nov 19, 2020

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

@hwillson
Copy link
Member

Let us know if this is still a concern with @apollo/client@latest - thanks!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants