NSCache crashing when memory limit is reached (only on iOS 7)

前端 未结 2 1008
-上瘾入骨i
-上瘾入骨i 2020-12-31 15:11

We are using NSCache for UIImages in our app. This works fine on iOS versions smaller than 7. When a memory warning occurs, NSCache releases objects as intended. However, on

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-31 15:58

    The NSCache object removes its data basing on its own rules. That doesn't mean that it will release content during a memory warning.
    Here what the doc states:

    The NSCache class incorporates various auto-eviction policies, which ensure that a cache doesn’t use too much of the system’s memory. If memory is needed by other applications, these policies remove some items from the cache, minimizing its memory footprint.

    Most probably the changed some policies in iOS7. You can remove all contents by listening to memory warning notification. I link this answer for sake of completeness.

提交回复
热议问题