react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Memory leak at JavaModuleWrapper.mModuleHolder

Open panda912 opened this issue 4 years ago • 10 comments

I got a memory leak on the Android platform when I launch a ReactActivity and finish it.

Description

LeakCanary report a memory leak when i launch a ReactActivity and finish it subsequently.

leakcanary

React Native version:

react-native info
F:\AwesomeProject>yarn react-native info
yarn run v1.5.1
$ F:\AwesomeProject\node_modules\.bin\react-native info
info Fetching system and libraries information...
System:
    OS: Windows 10 10.0.18362
    CPU: (4) x64 Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
    Memory: 6.43 GB / 15.89 GB
  Binaries:
    Node: 12.18.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.5.1 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 6.14.5 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK: Not Found
  IDEs:
    Android Studio: Version  3.6.0.0 AI-192.7142.36.36.6308749
  Languages:
    Java: 1.8.0_201 - C:\Program Files\Java\jdk1.8.0_201\bin\javac.EXE
    Python: 3.8.3 - C:\Python38\python.EXE
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.11.0 => 16.11.0
    react-native: 0.62.2 => 0.62.2
  npmGlobalPackages:
    *react-native*: Not Found
Done in 4.36s.

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

  1. Create a AwesomeProject via npx react-native init AwesomeProject;
  2. Create a new activity called LauncherActivity as the launcher activity of App, and activity's layout contains a button for click jump to MainActivity, of cause need delete the MainActivity's intent-filter in AndroidManifest.xml;
  3. Click LauncherActivity's button jump to MainActivity and then back to LauncherActivity and then back to system launcher, a memory leak occurs.

Expected Results

don't leak.

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

LauncherActivity.java
package com.awesomeproject;

import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class LauncherActivity extends AppCompatActivity {
  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_launcher);

    findViewById(R.id.button).setOnClickListener(v ->
        startActivity(new Intent(this, MainActivity.class)));
  }
}
activity_launcher.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"
  tools:context=".LauncherActivity">

  <Button
    android:id="@+id/button"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="jump to MainActivity" />

</LinearLayout>
MainActivity.java
package com.awesomeproject;

import androidx.annotation.Nullable;

import com.facebook.react.ReactActivity;

public class MainActivity extends ReactActivity {
  @Nullable
  @Override
  protected String getMainComponentName() {
    return "AwesomeProject";
  }
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.awesomeproject">

  <uses-permission android:name="android.permission.INTERNET" />

  <application
    android:name=".MainApplication"
    android:allowBackup="false"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:theme="@style/AppTheme">
    <activity
      android:name=".LauncherActivity"
      android:label="@string/app_name"
      android:launchMode="singleTask"
      android:windowSoftInputMode="adjustResize">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    <activity
      android:name=".MainActivity"
      android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
      android:label="@string/app_name"
      android:windowSoftInputMode="adjustResize" />
    <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
  </application>

</manifest>

panda912 avatar Jul 07 '20 07:07 panda912

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

stale[bot] avatar Oct 12 '20 02:10 stale[bot]

how to fix the problem?

kaelli avatar Oct 14 '20 08:10 kaelli

how to deal it?

DeveloperZH avatar Oct 28 '20 09:10 DeveloperZH

how to deal it?

xiedong6688 avatar Nov 16 '20 09:11 xiedong6688

how to deal it?

xiedong6688 avatar Nov 16 '20 09:11 xiedong6688

Did anyone get solutions?

AjayShivanagol avatar Dec 14 '20 14:12 AjayShivanagol

it still require the community's attention. Any news around fix?

UserSty avatar Sep 22 '21 13:09 UserSty

how to fix the problem?

jiantao88 avatar Oct 26 '21 02:10 jiantao88

Still need to fix.. exists in latest version as well.

Just adding my Analysis : I just found when we start React native app after first time then it is trying to remove the re What I found react-native view keep activity ref in mTagsToViews and trying to remove reference of last time opened React activity when we opened it subsequently next time. Ideally it should be removed when we close the application last time itself.

image

ashish03399 avatar Dec 02 '21 09:12 ashish03399

Any updates? This is still an issue for me.

spinoza1791 avatar Nov 04 '22 14:11 spinoza1791

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[bot] avatar May 24 '23 05:05 github-actions[bot]

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

github-actions[bot] avatar May 31 '23 05:05 github-actions[bot]

Facing same issue

satheshrgs-rksv avatar Jun 28 '24 09:06 satheshrgs-rksv

same issue

RN 0.69 I created a question on StackOverflow

NetPumi2 avatar Jul 02 '24 15:07 NetPumi2