Skip to content

自定义ImageDownloader时可能造成内存泄露 #235

@dopcn

Description

@dopcn
Contributor

在 ImageDownloader 里 session 是一个 strong property
private var session: NSURLSession?
在 ImageDownloader 的 init 里

session = NSURLSession(configuration: sessionConfiguration, delegate: self, delegateQueue: NSOperationQueue.mainQueue())

NSURLSession 的文档提到

IMPORTANT
The session object keeps a strong reference to the delegate until your app exits or explicitly invalidates the session. If you do not invalidate the session by calling the invalidateAndCancel or finishTasksAndInvalidate method, your app leaks memory until it exits.

defaultDownloader 是不会 deinit 的单例所以不影响,但是如果自定义 ImageDownloader 有可能会造成内存泄露

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @onevcat@dopcn

    Issue actions

      自定义ImageDownloader时可能造成内存泄露 · Issue #235 · onevcat/Kingfisher