rs/SDWebImage — pull request #791 by DimaVartanian (2014-07-04 21:26:47+00:00)
Title: Add a secondary weak memory cache to improve speed and decrease memory usage

Hey guys! This addition to the project can improve speed and significantly reduce memory usage in cases where the regular memory cache has been cleared but images it once held need to be reloaded.

**Consider the following case:**
1. An image is loaded and retained by ImageView1 (as well as added to the memory cache and disk cache)
2. Sometime later, the memory cache is cleared (possibly due to a memory warning)
3. ImageView2 loads the same image ImageView1 loaded earlier. The memory cache does not contain it so it is either reloaded from the disk cache, or downloaded again. In either case, a brand new UIImage is created, effectively resulting in 2 copies of the same image sitting in memory.

With this addition, all downloaded images are also referenced by the secondary weak memory cache (so they are not retained) and reused when possible to prevent a single image from ever being duplicated by SDWebImage.

**Sample**
To see the fix in action, you can download this sample project: http://cl.ly/2J3s0z2e2m2C
Move the comment in the podfile to switch between my fixed fork and the current latest commit in master.

Open the app and trigger the case by pushing a new view and then triggering a memory warning. Repeat this and watch the effects in Instruments: The allocations for `UIImage` continue to rise (In the Allocations instrument) and the Virtual Memory usage (in the Memory Monitor instruments) rises by several mb with each additional load. Switch to my fork and you will notice the UIImage only ever gets created once no matter what you do, and memory usage remains relatively static (rising very slowly due to multiple views and view controllers being allocated).