Add autoreleasepool to DisplayLinkCallback to release objects
This commit is contained in:
parent
10d06f6a33
commit
73c7e267a9
|
@ -269,22 +269,24 @@ static BOOL kSDDisplayLinkUseTargetTimestamp = NO; // Use `next` fire time, or `
|
||||||
|
|
||||||
#if SD_MAC
|
#if SD_MAC
|
||||||
static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeStamp *inNow, const CVTimeStamp *inOutputTime, CVOptionFlags flagsIn, CVOptionFlags *flagsOut, void *displayLinkContext) {
|
static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeStamp *inNow, const CVTimeStamp *inOutputTime, CVOptionFlags flagsIn, CVOptionFlags *flagsOut, void *displayLinkContext) {
|
||||||
// CVDisplayLink callback is not on main queue
|
@autoreleasepool {
|
||||||
// Actually `SDWeakProxy` but not `SDDisplayLink`
|
// CVDisplayLink callback is not on main queue
|
||||||
SDDisplayLink *object = (__bridge SDDisplayLink *)displayLinkContext;
|
// Actually `SDWeakProxy` but not `SDDisplayLink`
|
||||||
if (!object) return kCVReturnSuccess;
|
SDDisplayLink *object = (__bridge SDDisplayLink *)displayLinkContext;
|
||||||
// CVDisplayLink does not use runloop, but we can provide similar behavior for modes
|
if (!object) return kCVReturnSuccess;
|
||||||
// May use `default` runloop to avoid extra callback when in `eventTracking` (mouse drag, scroll) or `modalPanel` (modal panel)
|
// CVDisplayLink does not use runloop, but we can provide similar behavior for modes
|
||||||
NSString *runloopMode = object.runloopMode;
|
// May use `default` runloop to avoid extra callback when in `eventTracking` (mouse drag, scroll) or `modalPanel` (modal panel)
|
||||||
if (![runloopMode isEqualToString:NSRunLoopCommonModes] && ![runloopMode isEqualToString:NSRunLoop.mainRunLoop.currentMode]) {
|
NSString *runloopMode = object.runloopMode;
|
||||||
|
if (![runloopMode isEqualToString:NSRunLoopCommonModes] && ![runloopMode isEqualToString:NSRunLoop.mainRunLoop.currentMode]) {
|
||||||
|
return kCVReturnSuccess;
|
||||||
|
}
|
||||||
|
CVTimeStamp outputTime = inOutputTime ? *inOutputTime : *inNow;
|
||||||
|
// `SDWeakProxy` is weak, so it's safe to dispatch to main queue without leak
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
object.outputTime = outputTime;
|
||||||
|
[object displayLinkDidRefresh:(__bridge id)(displayLink)];
|
||||||
|
});
|
||||||
return kCVReturnSuccess;
|
return kCVReturnSuccess;
|
||||||
}
|
}
|
||||||
CVTimeStamp outputTime = inOutputTime ? *inOutputTime : *inNow;
|
|
||||||
// `SDWeakProxy` is weak, so it's safe to dispatch to main queue without leak
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
|
||||||
object.outputTime = outputTime;
|
|
||||||
[object displayLinkDidRefresh:(__bridge id)(displayLink)];
|
|
||||||
});
|
|
||||||
return kCVReturnSuccess;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue