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

[Android] memory leak in Android #35890

Closed
feiyin0719 opened this issue Jan 19, 2023 · 2 comments
Closed

[Android] memory leak in Android #35890

feiyin0719 opened this issue Jan 19, 2023 · 2 comments
Labels
Needs: Triage 🔍 Platform: Android Android applications. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@feiyin0719
Copy link

feiyin0719 commented Jan 19, 2023

Description

When we Integration RN as App SubActivity, if we close the Activity, it will cause memory leak

Explain Defect

since 0.65, when call dispatchViewUpdates, we add judge mNumRootViews>0
image
When we call removeRootView, it will decrease the mNumRootViews before dispatchViewUpdates
image
So when we remove the last rootview, it will skip call dispatchViewUpdates and do not remove it, it will cause memory leak

Version

0.65 - ~

Output of npx react-native info

N/A

Steps to reproduce

  1. Integrate RN as part Activity of APP(do not use RN as MainActivity)
  2. open RN Activity
  3. close RN Activity
    it will cause memory leak

Snack, code example, screenshot, or link to a repository

code example
https://github.com/feiyin0719/RNMemoryLeakAndroid

@react-native-bot react-native-bot added the Platform: Android Android applications. label Jan 19, 2023
facebook-github-bot pushed a commit that referenced this issue Feb 8, 2023
Summary:
fix memory leak in Android
The issues link: #35890
Explain Defect
since 0.65, when call dispatchViewUpdates, we add judge mNumRootViews>0
<img width="531" alt="image" src="https://user-images.githubusercontent.com/20136688/213394240-4c284df4-27de-494e-8eed-8e5f30796cce.png">
When we call removeRootView, it will decrease the mNumRootViews before dispatchViewUpdates
<img width="430" alt="image" src="https://user-images.githubusercontent.com/20136688/213394611-d47ab49f-fc7a-4dd1-9836-fe667d655660.png">
So when we remove the last rootview, it will skip call dispatchViewUpdates and do not remove it, it will cause memory leak
Explain Fix
We should use the original root view num to judge, we can get it from NativeViewHierarchyManager

## Changelog
[ANDROID] [FIXED] - fix memory leak in Android
<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

Pull Request resolved: #35889

Reviewed By: christophpurrer

Differential Revision: D42636805

Pulled By: sshic

fbshipit-source-id: 76845b5c1fbdeaf1ebe990356e82059dc1e5b46e
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this issue May 22, 2023
Summary:
fix memory leak in Android
The issues link: facebook#35890
Explain Defect
since 0.65, when call dispatchViewUpdates, we add judge mNumRootViews>0
<img width="531" alt="image" src="https://user-images.githubusercontent.com/20136688/213394240-4c284df4-27de-494e-8eed-8e5f30796cce.png">
When we call removeRootView, it will decrease the mNumRootViews before dispatchViewUpdates
<img width="430" alt="image" src="https://user-images.githubusercontent.com/20136688/213394611-d47ab49f-fc7a-4dd1-9836-fe667d655660.png">
So when we remove the last rootview, it will skip call dispatchViewUpdates and do not remove it, it will cause memory leak
Explain Fix
We should use the original root view num to judge, we can get it from NativeViewHierarchyManager

## Changelog
[ANDROID] [FIXED] - fix memory leak in Android
<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

Pull Request resolved: facebook#35889

Reviewed By: christophpurrer

Differential Revision: D42636805

Pulled By: sshic

fbshipit-source-id: 76845b5c1fbdeaf1ebe990356e82059dc1e5b46e
@github-actions
Copy link

github-actions bot commented Aug 6, 2023

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Aug 6, 2023
@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Triage 🔍 Platform: Android Android applications. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

2 participants