Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More flexible Resource cache eviction policy #31

Closed
pcantrell opened this issue Jan 5, 2016 · 3 comments · Fixed by #61
Closed

More flexible Resource cache eviction policy #31

pcantrell opened this issue Jan 5, 2016 · 3 comments · Fixed by #61

Comments

@pcantrell
Copy link
Member

Resources are currently eligible for deallocation on a low memory event. This works fine in most iOS apps, but (1) will not work on desktop apps, where low memory events do not exist, and (2) may cause memory churn for apps cycling rapidly through many resources.

WeakCache should support a more flexible eviction policy — perhaps akin to NSCache, perhaps more rule-based and resource-aware.

@pcantrell pcantrell mentioned this issue Jan 5, 2016
5 tasks
@onekiloparsec
Copy link
Contributor

That's definitely something we must work on for the desktop, I agree. NSCache has 2 properties we could build upon, maybe?

  • var totalCostLimit: Int, The maximum total cost that the cache can hold before it starts evicting objects
  • var countLimit: Int, The maximum number of objects the cache should hold

@pcantrell
Copy link
Member Author

I decided not to implement WeakCache using NSCache because of the complexity of the latter. As Matt Thompson put it, it’s “kind of a hot mess.” In particular, I was concerned about making Siesta’s strong → weak transition work in terms of NSDiscardableContent. The trick is that WeakCache needs to be able to to make refs go weak when the cache wants to discard them, but not actually remove them from the cache until the weak ref goes nil. I investigated a while, and it looked like it might conceivably be possible to make NSCache do this, but it would have to rely on dubious assumptions about the exact sequence of calls and internal behavior. Thus no NSCache.

@onekiloparsec
Copy link
Contributor

Thanks for the interesting read. I was just suggesting taking these NSCache concepts, but not NSCache itself. I'm sure you've studied the subject a lot more than me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants