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

Memory leak when reloading the app with Results/List Object listeners #2378

Closed
dkpalmer opened this issue May 21, 2019 · 9 comments
Closed

Comments

@dkpalmer
Copy link

dkpalmer commented May 21, 2019

Goals

Use Results/List Object listeners during development of a React Native app. This requires restarting the simulator or force-closing the app on device after a certain number of reloads.

Expected Results

Reloading the app during development (DEV mode) should not leak.

Actual Results

Memory leaks when dev-reloading the app with listeners on RealmResults and List objects. It does not leak on listeners on the Realm instance.

Steps to Reproduce

  • Call addListener on either a RealmResults object or a List object.
  • Reload the app (CMD+R)
  • See that memory climb

Code Sample

I created a fresh React Native app to demonstrate the issue at https://github.com/dkpalmer/realm-rn-reload-leak/. Inside App.js there are 3 cases within componentWillMount:

Does not leak when reloading: (1) Realm listener

Does leak when reloading: (2) Results listener and (3) List object listener

Assuming you have the RN CLI and Xcode installed, app can be run by cloning, installing dependencies, and running react-native run-ios.

Version of Realm and Tooling

  • Realm JS SDK Version: 2.27.0 and 2.28.0
  • Node or React Native: RN 0.59
  • Client OS & Version: iOS
  • Which debugger for React Native: DEV Perf Monitor
@dkpalmer
Copy link
Author

Also, I have tried looking at this from the RN side about any sort of cleanup opportunities before the bundle gets reloaded. Unfortunately, it doesn't look like there is a good option on that side: facebook/react-native#9773

@dkpalmer
Copy link
Author

Quick bump. Does anyone have any insights on the difference between a Realm Listener and a Results/Object listener and why the latter two would retain after reloading the JavaScript bundle, and/or suggestions on how to work around this?

@pedrobertao
Copy link

pedrobertao commented Jun 14, 2019

I have similar a problem with my project. On Android when we started to use listeners the App would just crash after a couple of reloads.

@kneth
Copy link
Contributor

kneth commented Aug 19, 2019

From facebook/react-native#9773 it sounds virtually impossible to make a solution which works every time.

Removing all listeners in componentDidMount() (before everything else) might be a work-around.

@dkpalmer
Copy link
Author

@kneth Do you have insights why Results and List object listeners do not leak?

@kneth
Copy link
Contributor

kneth commented Sep 23, 2019

@dkpalmer Results and List are based by Realm (the underlaying database engine) so they are native (C++) resources. Such resources are probably reclaimed by the operating system - even at reload. But the listener lives in the JS engine, and seems to survive a reload. I have label this issue as a bug as I believe listeners should be reclaimed too.

@SDSLeon
Copy link

SDSLeon commented Apr 21, 2021

Still an issue. Found that old JSContext is not destroyed when addListener is present on Results;
image
image

@bmunkholm
Copy link
Contributor

This may be resolved with our Hermes support. Will have to verify.

@kneth
Copy link
Contributor

kneth commented Oct 20, 2022

We have released v11.0.0 which has a complete rewrite of the integration with JSC. I am closing the issue, and ask you to upgrade. If the issue is still observed, please create a new issue.

@sync-by-unito sync-by-unito bot closed this as completed Oct 20, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 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

7 participants