Skip to content

Commit

Permalink
WeakPtrFactory should be destroyed before any other members. (flutter…
Browse files Browse the repository at this point in the history
  • Loading branch information
yx-mike committed Jan 18, 2022
1 parent 5c65fab commit 1cd2331
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions shell/platform/darwin/ios/framework/Source/FlutterEngine.mm
Expand Up @@ -206,6 +206,10 @@ - (void)dealloc {
object:self
userInfo:nil];

// It will be destroyed and invalidate its weak pointers
// before any other members are destroyed.
_weakFactory.reset();

/// nil out weak references.
[_registrars
enumerateKeysAndObjectsUsingBlock:^(id key, FlutterEngineRegistrar* registrar, BOOL* stop) {
Expand Down
Expand Up @@ -46,6 +46,10 @@ - (void)addSecondaryResponder:(nonnull id<FlutterKeySecondaryResponder>)responde
}

- (void)dealloc {
// It will be destroyed and invalidate its weak pointers
// before any other members are destroyed.
_weakFactory.reset();

[_primaryResponders removeAllObjects];
[_secondaryResponders removeAllObjects];
[_primaryResponders release];
Expand Down
Expand Up @@ -236,6 +236,10 @@ + (NSData*)createTxtData:(NSURL*)url {
}

- (void)dealloc {
// It will be destroyed and invalidate its weak pointers
// before any other members are destroyed.
_weakFactory.reset();

[_delegate stopService];
[_url release];

Expand Down
Expand Up @@ -779,6 +779,10 @@ - (void)deregisterNotifications {
}

- (void)dealloc {
// It will be destroyed and invalidate its weak pointers
// before any other members are destroyed.
_weakFactory.reset();

[self removeInternalPlugins];
[self deregisterNotifications];
[super dealloc];
Expand Down
Expand Up @@ -99,12 +99,12 @@ class AccessibilityBridge final : public AccessibilityBridgeIos {
int32_t last_focused_semantics_object_id_;
fml::scoped_nsobject<NSMutableDictionary<NSNumber*, SemanticsObject*>> objects_;
fml::scoped_nsprotocol<FlutterBasicMessageChannel*> accessibility_channel_;
fml::WeakPtrFactory<AccessibilityBridge> weak_factory_;
int32_t previous_route_id_;
std::unordered_map<int32_t, flutter::CustomAccessibilityAction> actions_;
std::vector<int32_t> previous_routes_;
std::unique_ptr<IosDelegate> ios_delegate_;

fml::WeakPtrFactory<AccessibilityBridge> weak_factory_; // Must be the last member.
FML_DISALLOW_COPY_AND_ASSIGN(AccessibilityBridge);
};

Expand Down
Expand Up @@ -46,11 +46,11 @@ void PostAccessibilityNotification(UIAccessibilityNotifications notification,
platform_views_controller_(platform_views_controller),
last_focused_semantics_object_id_(kSemanticObjectIdInvalid),
objects_([[NSMutableDictionary alloc] init]),
weak_factory_(this),
previous_route_id_(0),
previous_routes_({}),
ios_delegate_(ios_delegate ? std::move(ios_delegate)
: std::make_unique<DefaultIosDelegate>()) {
: std::make_unique<DefaultIosDelegate>()),
weak_factory_(this) {
accessibility_channel_.reset([[FlutterBasicMessageChannel alloc]
initWithName:@"flutter/accessibility"
binaryMessenger:platform_view->GetOwnerViewController().get().engine.binaryMessenger
Expand Down

0 comments on commit 1cd2331

Please sign in to comment.