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

[Feature] add auto purge on memory event #1141

Conversation

rromanchuk
Copy link
Contributor

This will probably be more controversial (it shouldn't be though) so i separated it from #1140

Inspired from
http://stackoverflow.com/a/19549090/775762

related to #538

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
…cache eviction.
@markrickert
Copy link

I like this, but do we want to remove ALL objects? Is there a way to remote just everything but the most recently cached n objects?

@rromanchuk
Copy link
Contributor Author

@markrickert yeah that would be ideal, but from what i can tell NSCache is like angsty teenager and it's eviction policies are just suggestions. I'm still uncomfortable with this because SDWebImage should never be causing system memory events. I found this actually can be managed with #1140 At this point the implementer has clearly mismanaged his memory and it's already too late to be algorithmic about it.

For over a year I have been fighting a bug where a long session would run up the memory and crash/shutdown when a memory intensive action followed. I was always under the assumption that this was perfectly normal to run up this cache as the system would reclaim it when needed, i figured it was just some memory leak inside other libraries like GPUImage when in reality NSCache would drive up memory pressure and the device would send a memory warning, NSCache would ignore it, and the app would explode on a memory intensive alloc.

I hate this PR, but short of completely turning off NSCache as #1130 or rewriting a real LRU eviction policy, we are being terrible netizens at the moment.

A good start might be to leave a message in the README about carefully configuring SDWebImage on the context of the app and to carefully monitor memory so that maximum cost and count limit are set correctly

@@ -48,6 +48,11 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
@property (assign, nonatomic) NSUInteger maxMemoryCost;

/**
* The maximum number of objects the cache should hold.
*/
@property (assign, nonatomic) NSUInteger maxMemoryCountLimit;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was part of another PR right?

@rs
Copy link
Member

rs commented May 12, 2015

I agree, the right fix is to implement an LRU cache. I don't have the bandwidth to do that right know, but if someone want to send a PR, I have the feeling that a lot of people would be grateful.

In the meantime I'm gonna accept this PR as it is a good meantime tradeoff. Could you please remove the part of the PR that belongs to anothers?

@rromanchuk
Copy link
Contributor Author

closing for #1143

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 this pull request may close these issues.

None yet

6 participants