{"action":"created","issue":{"url":"https://api.github.com/repos/rs/SDWebImage/issues/250","repository_url":"https://api.github.com/repos/rs/SDWebImage","labels_url":"https://api.github.com/repos/rs/SDWebImage/issues/250/labels{/name}","comments_url":"https://api.github.com/repos/rs/SDWebImage/issues/250/comments","events_url":"https://api.github.com/repos/rs/SDWebImage/issues/250/events","html_url":"https://github.com/rs/SDWebImage/issues/250","id":9286667,"number":250,"title":"SDImageCache not clearing","user":{"login":"JaapManenschijn","id":2803359,"avatar_url":"https://avatars.githubusercontent.com/u/2803359?v=3","gravatar_id":"","url":"https://api.github.com/users/JaapManenschijn","html_url":"https://github.com/JaapManenschijn","followers_url":"https://api.github.com/users/JaapManenschijn/followers","following_url":"https://api.github.com/users/JaapManenschijn/following{/other_user}","gists_url":"https://api.github.com/users/JaapManenschijn/gists{/gist_id}","starred_url":"https://api.github.com/users/JaapManenschijn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JaapManenschijn/subscriptions","organizations_url":"https://api.github.com/users/JaapManenschijn/orgs","repos_url":"https://api.github.com/users/JaapManenschijn/repos","events_url":"https://api.github.com/users/JaapManenschijn/events{/privacy}","received_events_url":"https://api.github.com/users/JaapManenschijn/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/rs/SDWebImage/milestones/2","html_url":"https://github.com/rs/SDWebImage/milestones/Future","labels_url":"https://api.github.com/repos/rs/SDWebImage/milestones/2/labels","id":693613,"number":2,"title":"Future","description":"this is the backlog, triaged issues that are not yet scheduled","creator":{"login":"bpoplauschi","id":154913,"avatar_url":"https://avatars.githubusercontent.com/u/154913?v=3","gravatar_id":"","url":"https://api.github.com/users/bpoplauschi","html_url":"https://github.com/bpoplauschi","followers_url":"https://api.github.com/users/bpoplauschi/followers","following_url":"https://api.github.com/users/bpoplauschi/following{/other_user}","gists_url":"https://api.github.com/users/bpoplauschi/gists{/gist_id}","starred_url":"https://api.github.com/users/bpoplauschi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bpoplauschi/subscriptions","organizations_url":"https://api.github.com/users/bpoplauschi/orgs","repos_url":"https://api.github.com/users/bpoplauschi/repos","events_url":"https://api.github.com/users/bpoplauschi/events{/privacy}","received_events_url":"https://api.github.com/users/bpoplauschi/received_events","type":"User","site_admin":false},"open_issues":30,"closed_issues":111,"state":"open","created_at":"2014-06-17T14:15:16Z","updated_at":"2016-06-07T04:50:39Z","due_on":null,"closed_at":null},"comments":16,"created_at":"2012-12-14T14:47:17Z","updated_at":"2016-06-08T11:03:15Z","closed_at":"2014-10-29T13:55:50Z","body":"With the latest version of SDWebImage, calling something like:\r\n[[SDImageCache sharedImageCache] clearMemory] does not actually clear your image cache.\r\n\r\nThis has been keeping me busy for a bit, as I wanted to force my program to always load the image from the web and not get it from cache. \r\nI came to a point where I used [[SDImageCache sharedImageCache] queryDiskCacheForKey: done:] ,after clearing the cache first, and it would not find anything. \r\nThen on the next line i'd use [imageView setImageWithURL: placeholderImage: completed:], which you'd expect to load the image from the web, as the image wasn't found previously. \r\nHowever, it'd still show the old image from the memory (wtf?).\r\n\r\nI started browsing through the code and came up to the following:\r\nBoth SDImageCache and SDWebImageManager (used for downloading the image) have are singletons, as in they have a static sharedImageCache (or sharedManager) to get an instance of the class.\r\nIn the implementation of both classes, a new imageCache is created. So instead of having one imageCache across the classes, there's actually two imageCaches.\r\n\r\nClearing the cache through [[SDImageCache sharedImageCache] clearMemory] does clear a cache. But it's not the cache you'd want cleared.\r\n\r\nI resolved my problem by changing the implementation of SDWebImageManager slightly.\r\nI changed the init method a bit. I replaced the line:\r\n_imageCache = SDImageCache.new;\r\n\r\nwith the following:\r\n_imageCache = [SDImageCache sharedImagecache];\r\n\r\nThis way you'll have the same imageCache across both classes.\r\nI don't know if this is the way it is supposed to be, but it made sense (atleast for my case)."},"comment":{"url":"https://api.github.com/repos/rs/SDWebImage/issues/comments/224557376","html_url":"https://github.com/rs/SDWebImage/issues/250#issuecomment-224557376","issue_url":"https://api.github.com/repos/rs/SDWebImage/issues/250","id":224557376,"user":{"login":"handiansom","id":9835765,"avatar_url":"https://avatars.githubusercontent.com/u/9835765?v=3","gravatar_id":"","url":"https://api.github.com/users/handiansom","html_url":"https://github.com/handiansom","followers_url":"https://api.github.com/users/handiansom/followers","following_url":"https://api.github.com/users/handiansom/following{/other_user}","gists_url":"https://api.github.com/users/handiansom/gists{/gist_id}","starred_url":"https://api.github.com/users/handiansom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/handiansom/subscriptions","organizations_url":"https://api.github.com/users/handiansom/orgs","repos_url":"https://api.github.com/users/handiansom/repos","events_url":"https://api.github.com/users/handiansom/events{/privacy}","received_events_url":"https://api.github.com/users/handiansom/received_events","type":"User","site_admin":false},"created_at":"2016-06-08T11:03:15Z","updated_at":"2016-06-08T11:03:15Z","body":"@bpoplauschi   Thank you so much for your answer. It really helped me reduce memory usage.  "}}
{"actor":{"display_login":"handiansom"}}