This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Fix an issue that Flutter Engine can't be recycled as strongly referenced by __NSMallocBlock__ #13062
Closed
kangwang1988
wants to merge
1
commit into
flutter:master
from
XianyuTech:alf_master_flutterengine_memory_leak_fix
Closed
Fix an issue that Flutter Engine can't be recycled as strongly referenced by __NSMallocBlock__ #13062
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,6 @@ @interface FlutterEngine () <FlutterTextInputDelegate, FlutterBinaryMessenger> | |
| @property(nonatomic, readonly) NSMutableDictionary* pluginPublications; | ||
|
|
||
| @property(nonatomic, readwrite, copy) NSString* isolateId; | ||
| @property(nonatomic, retain) id<NSObject> flutterViewControllerWillDeallocObserver; | ||
| @end | ||
|
|
||
| @interface FlutterEngineRegistrar : NSObject <FlutterPluginRegistrar> | ||
|
|
@@ -118,7 +117,6 @@ - (void)dealloc { | |
|
|
||
| NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | ||
| [center removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; | ||
| [_flutterViewControllerWillDeallocObserver release]; | ||
|
|
||
| [super dealloc]; | ||
| } | ||
|
|
@@ -175,14 +173,11 @@ - (void)setViewController:(FlutterViewController*)viewController { | |
| _viewController = [viewController getWeakPtr]; | ||
| self.iosPlatformView->SetOwnerViewController(_viewController); | ||
| [self maybeSetupPlatformViewChannels]; | ||
| [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onFlutterVCWillDeallocNotif:) name:FlutterViewControllerWillDealloc object:viewController]; | ||
| } | ||
|
|
||
| self.flutterViewControllerWillDeallocObserver = | ||
| [[NSNotificationCenter defaultCenter] addObserverForName:FlutterViewControllerWillDealloc | ||
| object:viewController | ||
| queue:[NSOperationQueue mainQueue] | ||
| usingBlock:^(NSNotification* note) { | ||
| [self notifyViewControllerDeallocated]; | ||
| }]; | ||
| - (void)onFlutterVCWillDeallocNotif:(NSNotification *)aNotification { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: avoid abbreviations - maybe just |
||
| [self notifyViewControllerDeallocated]; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason to have this new method at all? Can you add a notification parameter to notifyViewControllerDeallocated (assuming this isn't exposed in a header, I'm not looking at the code at the moment) [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notifyViewControllerDeallocated:) name:FlutterViewControllerWillDealloc object:viewController];- (void)notifyViewControllerDeallocated:(NSNotification *)notification {Also, does this still need to dispatch to the mainQueue if this isn't the main queue? There's no guarantee about what queue the notification will be posted on. |
||
| } | ||
|
|
||
| - (void)notifyViewControllerDeallocated { | ||
|
|
@@ -638,6 +633,7 @@ - (instancetype)initWithPlugin:(NSString*)pluginKey flutterEngine:(FlutterEngine | |
| } | ||
|
|
||
| - (void)dealloc { | ||
| [[NSNotificationCenter defaultCenter] removeObserver:self]; | ||
| [_pluginKey release]; | ||
| [_flutterEngine release]; | ||
| [super dealloc]; | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't removing the observer for the previous viewController.