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 in Native Modules with RCT_EXPORT_METHOD #26972

Closed
nikolaytsigvintsev opened this issue Oct 23, 2019 · 2 comments
Closed

Memory leak in Native Modules with RCT_EXPORT_METHOD #26972

nikolaytsigvintsev opened this issue Oct 23, 2019 · 2 comments
Labels
Bug Needs: Author Feedback Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.

Comments

@nikolaytsigvintsev
Copy link

nikolaytsigvintsev commented Oct 23, 2019

Hi !

Problem:
Memory leak and application crash on RCT_EXPORT_METHOD

When developing a module, I ran into a memory leak problem in NativeModules.
A memory leak occurs when the resolve() function is called from the Objective-C module with data transfer to the JS function.

React Native version:
System:
OS: macOS Mojave 10.14.5
CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
Memory: 421.92 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 12.12.0 - /usr/local/bin/node
Yarn: 1.19.1 - /usr/local/bin/yarn
npm: 6.11.3 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 13.0, DriverKit 19.0, macOS 10.15, tvOS 13.0, watchOS 6.0
IDEs:
Xcode: 11.0/11A420a - /usr/bin/xcodebuild
npmPackages:
react: 16.9.0 => 16.9.0
react-native: 0.61.2 => 0.61.2
npmGlobalPackages:
react-native-cli: 2.0.1
iPad: 12.1

Steps To Reproduce

I wrote a test code:

FileReader.h

#ifndef FileReader_h
#define FileReader_h

#import <React/RCTBridgeModule.h>

@interface FileReader : NSObject <RCTBridgeModule>
@end

#endif /* FileReader_h */

FileReader.m

#import <Foundation/Foundation.h>
#import “FileReader.h”
#import <React/RCTLog.h>

@implementation FileReader

RCT_EXPORT_MODULE();

RCT_EXPORT_METHOD(read:(NSString *)read
                  resolver:(RCTPromiseResolveBlock)resolve
                  rejecter:(RCTPromiseRejectBlock)reject)
{
  NSLog(@"JS: start");
  @autoreleasepool {    
      NSMutableString *nameString = [[NSMutableString alloc] init];
      for (int i = 1; i <= 3000000; i++)
      {
       [nameString appendString:@"1234567890"];
      }
      NSLog(@"JS: send string");
    
    resolve(nameString);
  }
}
@end

FileReader.js

……..
import {NativeModules} from 'react-native';

const FileReader = NativeModules.FileReader;

const onRead= async () => {
  for (let i = 0; i < 1000; i++) {
    await FileReader.read('Start').then(response => {
        console.log('Step: ', i);
    });
  }
};
…….

Describe what you expected to happen:
I wish the memory leak disappeared

Videoreport:
https://www.dropbox.com/s/aq9nu44tcziqulb/Screen%20Recording%202019-10-23%20at%2017.06.14.mov?dl=0

Thanks!

@react-native-bot
Copy link
Collaborator

Thanks for submitting your issue. Can you take another look at your description and make sure the issue template has been filled in its entirety?

👉 Click here if you want to take another look at the Bug Report issue template.

@no-response
Copy link

no-response bot commented Mar 5, 2020

It's been three weeks since we asked for additional information from the author of this issue. As it happens, we don't have enough information to take action. We are going to close this issue, but please do not hesitate to open a new issue if you are still encountering this problem.

@no-response no-response bot closed this as completed Mar 5, 2020
@facebook facebook locked as resolved and limited conversation to collaborators Oct 2, 2021
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Oct 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Needs: Author Feedback Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

3 participants