Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: property week -> weak
  • Loading branch information
yimao009 committed Apr 25, 2022
commit 3904c0e35d9d2d344231b070794b93762421b532
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ @interface InAppPurchasePlugin ()
// Callback channel to dart used for when a function from the payment queue delegate is triggered.
@property(strong, nonatomic, readonly) FlutterMethodChannel *paymentQueueDelegateCallbackChannel;

@property(week, nonatomic, readonly) NSObject<FlutterTextureRegistry> *registry;
@property(weak, nonatomic, readonly) NSObject<FlutterTextureRegistry> *registry;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like registry is unused in the plugin code and can be completely removed. "messenger" can also be removed with a little tweak in the code.

And it looks like registrar can be weak as the engine should keep a strong reference to the registrar and plugin should out live the engine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in_app_purchase may not be a problem in pure flutter projects, but in projects that natively access flutter, the engine cannot be effectively released, resulting in memory leaks, for example:

@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (nonatomic, strong) FlutterEngineGroup *engines;
@end
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        self.engines = [[FlutterEngineGroup alloc] initWithName:@"" project:nil];
        return YES;
}

Controller A

- (IBAction)pushNext:(id)sender {
    NextViewController *vc = [[NextViewController alloc] initWithEntryPoint:nil];
    [self.navigationController pushViewController:vc animated:YES];
}

Controller B

// .h
@interface NextViewController : FlutterViewController
- (instancetype)initWithEntryPoint:(NSString *)point ;
@end
// .m 
- (instancetype)initWithEntryPoint:(NSString *)point {
    AppDelegate *delegate = ((AppDelegate *)([UIApplication sharedApplication].delegate));

    FlutterEngine *engine = [delegate.engines makeEngineWithEntrypoint:point libraryURI:nil];
    [GeneratedPluginRegistrant registerWithRegistry:engine];
    if (self = [super initWithEngine:engine nibName:nil bundle:nil]) {}
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.channel = [FlutterMethodChannel methodChannelWithName:@"normal" binaryMessenger:self.engine.binaryMessenger];
}

When I pop NextViewController , the flutter engine is not released, I found that in_app_purchase caused by debug memory graph.
The registry is not used, I don't know why it is written like this, I think it can be deleted.

@property(strong, nonatomic, readonly) NSObject<FlutterBinaryMessenger> *messenger;
@property(strong, nonatomic, readonly) NSObject<FlutterPluginRegistrar> *registrar;

Expand Down