NSCache and background

江枫思渺然 提交于 2019-11-30 06:47:30

In my case, that happened when objects stored in NSCache does not conform to NSDiscardableContent protocol. When I added the said protocol, eviction of objects when the app is entering background disappears.

In addition, based on source of NSCache.m I found here, objects that do not conform to NSDiscardableContent protocol are never removed at runtime even the app needs more memory and should evict some of its elements. Maybe that's the reason why non-NSDiscardableContent objects are evicted when the app is entering background because that's a good time for them to be evicted.

E. Thompson

The comments in this related post indicate that an NSCache is cleared when the app enters the background. NSCache is not evicting data

NSCache continues to be ridiculous. I've been an iOS dev since day 1 of the SDK and only just today I got bit by this and found this helpful post.

For all these years, I thought it was working like any normal cache should, but nope! I'll never use it again.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!