kean/DFImageManager

DFImageManagerImageLoader sometimes fails to cancel fetch operations

Closed this issue · 5 comments

kean commented

DFImageManagerImageLoader (private class) uses a single fetch operation for equivalent request. Executing operations are stored in a dictionary with wrapped requests as a keys. This dictionary is the only object that holds strong references to the operations.

Operations are removed from the dictionary in two places:

  1. When image task is cancelled and there are no remaining tasks that are subscribed to the operation
  2. When operation is complete

Operation's completion handler is called for cancelled operations. The problem arises when you start, cancel and then restart the same requests very fast. In that case there is a chance that DFImageManagerImageLoader would remove a second operation (for restarted request) when handling completion of the first operation (which was cancelled). The requests are the same, but operations are different. This would lead to the operation deallocation (actually deallocation of its wrapper) which would prevent DFImageManagerImageLoader from cancellation and reusing this operation later.

kean commented

Fixed 7491c82

@kean are you planning on releasing a new version soon? thanks

kean commented

@mythodeia yep, releasing it today. Going to drop sdwebimage? 😉

@kean 😮 oh come on! play nice! i admit we need a major update but time is always against us. And i have to admit your work is exceptional and tempting

kean commented

any contribution would be much appreciated :)