Giter Club home page Giter Club logo

Comments (3)

github-actions avatar github-actions commented on August 21, 2024
⚠ī¸ Missing Reproducible Example
ℹī¸ We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.

from react-native.

cortinico avatar cortinico commented on August 21, 2024

There is a memory leak in the dialog management code of React Native's new architecture. When the hide() method is called and the dialog is not currently showing, the ReactRootView is not removed from the view tree. This results in the ReactRootView holding a reference to the Activity, causing a memory leak.

Can you provide a valid repro an a screenshot from the memory profiler of Android Studio?

from react-native.

fannnzhang avatar fannnzhang commented on August 21, 2024

First, in my issue, I provided the memory leak path captured by LeakCanary. When looking at the code, this issue becomes very clear: Regardless of the state of the Dialog, mReactRootView will always be indirectly created and held by LogModule, and when ReactRootView is created, it holds a reference to the Activity. Therefore, the hide method of LogBoxDialogSurfaceDelegate must ensure that it is removed from the Activity. However, the current implementation of the hide method does not do this. When the dialog is not created or shown, it directly returns, causing the view to not release the Activity reference, which leads to a memory leak.

To reproduce this issue is very simple. You just need to start by creating a Native Activity in the React Native Android template project, then navigate to a ReactActivity, and finally return to the main Activity from the ReactActivity. This will reliably reproduce the memory leak. Additionally, this reproduction path may also uncover other memory leaks under the new architecture. I suggest conducting similar tests as soon as possible and fixing the related issues.
My local fix code like this:

  @Override
  public void hide() {
    if (isShowing()) {
      mDialog.dismiss();
    }

    if (mReactRootView != null && mReactRootView.getParent() != null) {
      ((ViewGroup) mReactRootView.getParent()).removeView(mReactRootView);
    }
    mDialog = null;
  }

from react-native.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤ī¸ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.