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

RCTBridge never dealloc #15462

Closed
punan opened this issue Aug 11, 2017 · 9 comments
Closed

RCTBridge never dealloc #15462

punan opened this issue Aug 11, 2017 · 9 comments
Labels
Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@punan
Copy link

punan commented Aug 11, 2017

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

  1. react-native -v: 0.47.0
  2. node -v: v8.1.2
  3. npm -v: 5.3.0
  4. yarn --version: not use

Then, specify:

  • Target Platform: iOS
  • Development Operating System: macOS
  • Build tools: Xcode

Steps to Reproduce

(Write your steps here:)

1.create new project
react-native init demo
2. create a new ViewController, and delete all the code in AppDelegate
3.add the RCTRootView to ViewController

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSURL *jsCodeLocation;
  
    jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
  
    RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                        moduleName:@"demo"
                                                 initialProperties:nil
                                                     launchOptions:nil];
  rootView.frame = self.view.frame;
  [self.view addSubview:rootView];
}

@end

4、run the project

Expected Behavior

When the ViewController has been popped from UINavigationController, the RCTRootView and RCTBridge has to call dealloc methos

Actual Behavior

ViewController and RCTRootView has called dealloc method, but RCTBridge hasn't call dealloc, become leak.
screen shot 2017-08-11 at 3 50 35 pm
I use debug memory graph, it shows ViewControll and RCTRootView has been released, but when open ViewController again and again, the number of RCTBrigde will increase, the memory also increase

Reproducible Demo

Demo Link
I try to fix the issue, add [_bridge invalidate] to RCTRootView dealloc method. It works, RCTBridge calls dealloc methods when RCTRootView dealloc.

RCTRootView

- (void)dealloc
{
  [[NSNotificationCenter defaultCenter] removeObserver:self];
  [_contentView invalidate];
  [_bridge invalidate];
}
@shergin
Copy link
Contributor

shergin commented Sep 1, 2017

Probably fixed in 1f9fc0e .

@stale
Copy link

stale bot commented Oct 31, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Oct 31, 2017
@stale stale bot closed this as completed Nov 7, 2017
@sdyxch
Copy link

sdyxch commented Nov 8, 2017

same issue, The ViewController and RCTRootView has been released, but RCTBridge never.
I rollback to BatchedBridge, it works..
for react-native: 0.49.5

@312362115
Copy link

still on 0.53.0

@edison0951
Copy link

still on 0.51.0

@edison0951
Copy link

We must set [_bridge invalidate] so that the relative resource can be release

@seuzxh
Copy link

seuzxh commented Apr 25, 2018

Same issue with version 0.54.2, RCTBridge cannot be dealloced
I found following codes will fix this issue

// RCTRootView.m
- (void)dealloc
{
  [[NSNotificationCenter defaultCenter] removeObserver:self];
  [_contentView invalidate];
 // Add following codes
  [_bridge invalidate];
  _bridge = nil;
}

But it seems RN doesn't want to fix this issue

@vvlee
Copy link

vvlee commented Jun 13, 2018

still on 0.55.4

But I don't agree with @seuzxh solution, that is because bridge maybe used to multi RCTRootView.

@arslan2012
Copy link

still on 0.56.0 lol wtf

@facebook facebook locked as resolved and limited conversation to collaborators Nov 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
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

8 participants