Skip to content

Commit

Permalink
[iOS] Fixes DisplayLinkManager leaks (#22194)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongwuzw committed Jan 21, 2021
1 parent 5cf3eae commit fd9a079
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 28 deletions.
Expand Up @@ -635,7 +635,7 @@ - (BOOL)createShell:(NSString*)entrypoint
}

- (void)initializeDisplays {
double refresh_rate = [[[DisplayLinkManager alloc] init] displayRefreshRate];
double refresh_rate = [DisplayLinkManager displayRefreshRate];
auto display = flutter::Display(refresh_rate);
_shell->OnDisplayUpdates(flutter::DisplayUpdateType::kStartup, {display});
}
Expand Down
Expand Up @@ -12,8 +12,6 @@

@interface DisplayLinkManager : NSObject

- (instancetype)init;

//------------------------------------------------------------------------------
/// @brief The display refresh rate used for reporting purposes. The engine does not care
/// about this for frame scheduling. It is only used by tools for instrumentation. The
Expand All @@ -23,7 +21,7 @@
///
/// @return The refresh rate in frames per second.
///
- (double)displayRefreshRate;
+ (double)displayRefreshRate;

@end

Expand Down
32 changes: 8 additions & 24 deletions shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.mm
Expand Up @@ -91,26 +91,16 @@ - (void)dealloc {

@end

@implementation DisplayLinkManager {
fml::scoped_nsobject<CADisplayLink> display_link_;
}

- (instancetype)init {
self = [super init];

if (self) {
display_link_ = fml::scoped_nsobject<CADisplayLink> {
[[CADisplayLink displayLinkWithTarget:self selector:@selector(onDisplayLink:)] retain]
};
display_link_.get().paused = YES;
}
@implementation DisplayLinkManager

return self;
}

- (double)displayRefreshRate {
+ (double)displayRefreshRate {
if (@available(iOS 10.3, *)) {
auto preferredFPS = display_link_.get().preferredFramesPerSecond; // iOS 10.0
fml::scoped_nsobject<CADisplayLink> display_link = fml::scoped_nsobject<CADisplayLink> {
[[CADisplayLink displayLinkWithTarget:[[DisplayLinkManager new] autorelease]
selector:@selector(onDisplayLink:)] retain]
};
display_link.get().paused = YES;
auto preferredFPS = display_link.get().preferredFramesPerSecond; // iOS 10.0

// From Docs:
// The default value for preferredFramesPerSecond is 0. When this value is 0, the preferred
Expand All @@ -131,10 +121,4 @@ - (void)onDisplayLink:(CADisplayLink*)link {
// no-op.
}

- (void)dealloc {
[display_link_.get() invalidate];

[super dealloc];
}

@end

0 comments on commit fd9a079

Please sign in to comment.