-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 - InMemoryCache and Optimism never deletes records #7086
Comments
@benjamn I'm not entirely sure how all of that works but I can help to fix it, just need few clues :) |
I believe we store |
#7013 Might be related to this |
The |
@benjamn I believe this issue should get more attention. Since we migrated a huge project to v3, we see multiple memory leaks. Here's another heap snapshot of a memory leak we chase, and caused by retained I think the 2 issues above might be related, and caused by the same issue, and @kamilkisiela 's issue is just one symptom of it. Both seems to be related to |
Inspired by @kamilkisiela's comment: #7149 (comment) Should fix #7149 and #7086.
Inspired by @kamilkisiela's comment: #7149 (comment) Should fix #7149 and #7086.
Inspired by @kamilkisiela's comment: #7149 (comment) Should fix #7149 and #7086.
Thanks to @dotansimha's reproduction and @kamilkisiela's proposed solution, I'm confident this leak is fixed in |
In a project I work on (used by milions of people) we use Electron and in every pop-out window, we pass a reference to
Window
object within an operation's context. Because thecallback
holds a reference toQueryInfo => ObservableQuery => ObservableQuery.options => options.context => context.window
we have a memory leak.Consumers open new windows every few minutes (it's a chat app) which adds more and more instances of
Window
.How to reproduce the issue:
Repository | Deployed app
Here, we use
dep
fromoptimism
package that creates aMap
:apollo-client/src/cache/inmemory/inMemoryCache.ts
Line 356 in 481b30d
When there's a new query,
InMemoryCache
runsbroadcastWatch
method in which it usesoptimism
.The
watchDep.dirty(c)
removes a record from theMap
apollo-client/src/cache/inmemory/inMemoryCache.ts
Line 375 in 481b30d
Later on in
broadcastWatch
, thewatchDep(c)
is called and it sets a new record in ourMap
:apollo-client/src/cache/inmemory/inMemoryCache.ts
Line 383 in 481b30d
The problem is that
c
which representsCache.WatchOptions
apollo-client/src/cache/core/types/Cache.ts
Lines 25 to 28 in 481b30d
is stored forever in the
Map
created in Optimism'sdep()
and thatcallback
is function that depends onQueryInfo
classapollo-client/src/core/QueryInfo.ts
Lines 246 to 251 in 481b30d
which depends directly on
ObservableQuery
class in which we store query's options operation's context.Versions
The text was updated successfully, but these errors were encountered: