Skip to content

Fix on macOS, SDAnimatedImagePlayer leaking SDDisplayLink instances and leaving CVDisplayLink threads running #3776

Description

@renewedvision-kh

New Issue Checklist

Issue Info

Info Value
Platform Name macos
Platform Version 15.1.1
SDWebImage Version 5.20.0
Integration Method SPM
Xcode Version 16.2
Repro rate 100%
Repro with our demo prj n/a
Demo project link n/a

Issue Description and Steps

When an SDAnimatedImagePlayer creates a SDDisplayLink in -[SDAnimatedImagePlayer displayLink] the SDDisplayLink is not released when the SDAnimatedImagePlayer is deallocated. This results in a proliferation of CVDisplayLink threads.

The current implementation of '-[SDAnimatedImagePlayer dealloc]' is:

- (void)dealloc {
    // Dereference the frame pool, when zero the frame pool for provider will dealloc
    [SDImageFramePool unregisterProvider:self.animatedProvider];
}

And I se nothing that would suggest that the SDDisplayLink is stopped or removed from the RunLoop. When I change the code to something link:

- (void)dealloc {
    // Dereference the frame pool, when zero the frame pool for provider will dealloc
    [SDImageFramePool unregisterProvider:self.animatedProvider];
    [_displayLink stop];
    [_displayLink removeFromRunLoop:[NSRunLoop mainRunLoop] forMode:_runLoopMode];
}

Then I no longer see a proliferation of CVDisplayLink threads (as seen in Xcode):
Screenshot 2024-12-12 at 4 30 29 PM

It is unclear if this is the correct solution to prevent the leak or if a better solution is available.

Metadata

Metadata

Assignees

No one assigned

    Labels

    leakMemory LeakmacOSAppKit for macOS

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions