diff --git a/src/cache/inmemory/inMemoryCache.ts b/src/cache/inmemory/inMemoryCache.ts index aa988941e1d..64a90cdac03 100644 --- a/src/cache/inmemory/inMemoryCache.ts +++ b/src/cache/inmemory/inMemoryCache.ts @@ -181,6 +181,11 @@ export class InMemoryCache extends ApolloCache { } return () => { this.watches.delete(watch); + this.watchDep.dirty(watch); + // Remove this watch from the LRU cache managed by the + // maybeBroadcastWatch OptimisticWrapperFunction, to prevent memory + // leaks involving the closure of watch.callback. + this.maybeBroadcastWatch.forget(watch); }; }