Skip to content

RCTBridge never dealloc #15462

Closed
Closed
@punan

Description

@punan

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];
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    StaleThere has been a lack of activity on this issue and it may be closed soon.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions