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
chrome://inspectorFoo class
@benjamn I can confirm that Cache.removeOptimistic is called but Foo is still there
I think that
holds a reference forever because it has no cleanup logic.
I think it's exactly the same issue we had https://github.com/apollographql/apollo-client/issues/7086
@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 [email protected] and can be tested by running either npm i optimism@latest or npm i @apollo/[email protected].
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.
Thanks, we're going to test it soon
should #7276 be merged into master too? It should minimize amount of potential memory leaks too
Most helpful comment
@kamilkisiela I've updated the
optimismlibrary so that it no longer holds ontoentry.argsarrays (see https://github.com/benjamn/optimism/pull/104), so memory leaks related to arguments passed to methods likeexecuteSelectionSetshould no longer be possible.Following your reproduction steps, I no longer see retainment paths for
Fooobjects with lines likeargs in Entry @1663111(or anything above it).These changes were published in
[email protected]and can be tested by running eithernpm i optimism@latestornpm i @apollo/[email protected].It might still be worthwhile to evict/forget
Entryobjects 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.