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

Possible memory leak with useQuery #7013

Closed
hlandao opened this issue Sep 13, 2020 · 7 comments
Closed

Possible memory leak with useQuery #7013

hlandao opened this issue Sep 13, 2020 · 7 comments

Comments

@hlandao
Copy link

hlandao commented Sep 13, 2020

Intended outcome:
Running the same query many times in React-Native shouldn't make the JS heap to grow

Actual outcome:
Running the same query many times causing JS heap to grow meaning there is a memory leak.

How to reproduce the issue:
Run the same query many times, even with fetchPolicy=network-only

This is the diff of snapshots of the heap (before and after running the same query 5 times). As you dan see objects are being retained and not cleaning up.
image

This is the tree of objects
image

I think it has to do something with maybeBroadcastWatch from inMemoryCache.ts

Does anyone experienced anything like that?
Versions
System:
OS: macOS 10.15.6
Binaries:
Node: 12.18.2 - ~/.nvm/versions/node/v12.18.2/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.5 - ~/.nvm/versions/node/v12.18.2/bin/npm
Browsers:
Chrome: 85.0.4183.102
Safari: 13.1.2
npmPackages:
@apollo/client: ^3.1.5 => 3.1.4
apollo-cache-persist: git@github.com:apollographql/apollo-cache-persist.git#0.2.0 => 0.1.1

@NathanSaunders01
Copy link

I'm having a similar issue with useQuery in React Native. The issue in my case seems to be when I add fetchPolicy: 'network-only' to it.

The initial load is fine but any updates to data in that query using cache.writeQuery will cause an infinite loop of reloading the component over and over again. If I then move to another screen which queries the same data again, it will cause an infinite loop of querying the same data over and over again.

In my case, I think it could be to do with the way React Navigation works with screens? When I move from the first screen to the next, the initial screen is still mounted with that first query so when I make the second query on the next page, I wonder if they re-trigger each-other over and over?

I didn't have this issue with apollo-client@2.6.10

@hlandao
Copy link
Author

hlandao commented Sep 29, 2020

@NathanSaunders01 I think in my case it happens with the default fetchPolicy as well as with network-only. However, with cache-only it does not happen.

@patsplat
Copy link

Have also observed this leak in a production server-side-rendering deployment.

@phryneas
Copy link
Member

Hi everyone!

We recently released the Apollo Client 3.9 beta, which should resolve quite a lot of memory leaks like this.

Could you please give it a test and report back? For more information, please see the announcement blog post.

@phryneas
Copy link
Member

phryneas commented Feb 6, 2024

Apollo Client 3.9 has been released finally, and I believe this issue should have been solved with it.

If you still see this happening with Apollo Client >=3.9, please open a new issue :)

@phryneas phryneas closed this as completed Feb 6, 2024
Copy link
Contributor

github-actions bot commented Feb 6, 2024

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.

Copy link
Contributor

github-actions bot commented Mar 9, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
For general questions, we recommend using StackOverflow or our discord server.

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

No branches or pull requests

6 participants