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

Can I explicitly trigger Siesta's low memory cleanup? #179

Closed
jordanpwood opened this issue Feb 5, 2017 · 3 comments
Closed

Can I explicitly trigger Siesta's low memory cleanup? #179

jordanpwood opened this issue Feb 5, 2017 · 3 comments

Comments

@jordanpwood
Copy link

I have an issue where I'm caching data that I've collected from two different sources, Siesta being one of them. That model class contains Resources which it is observing. When a low memory warning comes in, I release all my cached data which is currently not on the screen. However, I've found that there's no guarantee that my class's response to low memory happens before Siesta's, so the fact that my class was observing some Resources prevents Siesta from flushing its cached data.

The simplest thing for me to do would be to clean up my cache, then call Siesta's cleanup. Is that a reasonable approach, and if so, does Siesta allow it? I would otherwise have to reengineer my handling of Resources in order to toggle their observation state based on whether the user was looking at that data or not. I'd prefer to keep things simple and handle the unusual low memory case separately, if possible.

let me know what I can do, I'm still loving Siesta!

Jordan

@pcantrell
Copy link
Member

This is the perpetual problem with memory cleanup events — and with NotificationCenter in general, I suppose. There’s not an obvious good answer.

Siesta does internally listen for a MemoryWarningNotification notification which you could cheat and publish yourself. It is just UIApplicationDidReceiveMemoryWarning on iOS, however, which might send you into thrash mode.

I’d consider exposing a Service.flushUnusedResource() or similar, if that sounds like the best solution to your problem. Any further insights since you asked the question?

@jordanpwood
Copy link
Author

I punted on this problem and just stopped caching data not on the screen. 😞 This makes my VC a bit slower to draw than I like, but doesn't actually cause any additional network requests. Having access to something like a Service.flushUnusedResource() would still be my preferred solution.

@pcantrell
Copy link
Member

Having access to something like a Service.flushUnusedResource() would still be my preferred solution.

It’s a reasonable request, and easy enough to implement. We’ll need to give a little thought to what it should be called, whether it should be global or per service, and whether it exposes anything it shouldn’t.

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

No branches or pull requests

2 participants