Apollo-client: Memory Leak: Mutation + OptimisticResponse makes update function to leak

Created on 17 Nov 2020  路  4Comments  路  Source: apollographql/apollo-client

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

Most helpful comment

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

All 4 comments

@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

Was this page helpful?
0 / 5 - 0 ratings