Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.0+6

* Fixed a memory leak error For iOS.

## 0.3.0+5

* Migrates from `ui.hash*` to `Object.hash*`.
Expand Down
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(strong, nonatomic, readonly) NSObject<FlutterTextureRegistry> *registry;
@property(weak, nonatomic, readonly) NSObject<FlutterTextureRegistry> *registry;
Copy link
Copy Markdown
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
Copy Markdown
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: in_app_purchase_storekit
description: An implementation for the iOS platform of the Flutter `in_app_purchase` plugin. This uses the StoreKit Framework.
repository: https://github.com/flutter/plugins/tree/main/packages/in_app_purchase/in_app_purchase_storekit
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+in_app_purchase%22
version: 0.3.0+5
version: 0.3.0+6

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down