When is disk cache cleared on iOS? - ios

I'm using the cache to store a bunch of rendered thumbnails for my game. It can easily go up to 60MB if the user has all the content in the game.
I wonder if I need to clear this out myself? Does the OS do this for me, and if so when?
Thanks!

When I had an issue with the documents directory on IOS5 I found this article which discusses the cache amongst other subjects.
As I understand it; yes the OS handles the cache and it will clear it when disk space is low. What low actually means in size I do not know.

Related

How can I control cache of the DB4O

I have some difficulties to find documents about DB4O. How can I control cache of the DB4O? I think than its connection is expending all memory of our server. I want set the minimal cache configuration.
Could anyone recommend me some document or send me some examples?
I'm glad for anyone who can help.
If you already made the cache configuration like #Gamlor said, the problem can be a object corrupted, you can delete this object and defrag your database to improve performance
I would recommend looking at it with a profiler. Then you can see what kind of classes take up space.
A typical pitfall with db4o is that that a 'ObjectContainer' is kept open for a long time, with a high activation depth. Then a large part of your object graph is kept in memory.
Some nobs to try:
configuration.common().weakReferenceCollectionInterval(milli-secs);
How often db4o clears up it's weak reference cache system. If you lower that interval, cleans up more aggressive.
There is a file level cache. I think it's quite low by default. Anyway, here's setting:
Storage fileStorage = new FileStorage();
// A cache with 128 pages of 1024KB size, gives a 128KB cache
Storage cachingStorage = new CachingStorage(fileStorage,128,1024);
configuration.file().storage(cachingStorage);
Maybe there are more caches. I don't remember all of then.

What is the best way to Cache JSON request images for offline use?

I am new to networking and data caching in general. I am making a network request that returns me url strings which lead to images. I want to cache this data for offline use. What is the smartest way to do this using Apples frameworks(no third party libraries)?
Thank you!
If you do not want to use third-party libs you have only two options: write your own solution or use a NSURLCache
NSURLCache allows you to cache downloaded data in memory and on disk. The only issue with NSURLCache is that it does not guaranties everything you downloaded will be saved. For example it does not save (at least in iOS8) files that are bigger than 5% of the maximum disk usage. Also cache storage could be erased if device is out of the disk space. So NSURLCache usually is not suitable if you need a fully working offline solution. But it works great if you just need to reduce a network usage.
You could also read about NSURLCache here

What is the most appropriate way to cache arbitrary data in an iOS app?

I would like to cache some arbitrary data in my iOS app. I would like it to remain in memory for as long as possible, and fall back to long-term storage if the "in-memory" cache is going away (app is closing). Also, I would like the older items to get pushed to long-term storage once the "in-memory" cache fills up with newer, more-frequently-accessed items.
What libraries or frameworks would I need to use to add this functionality?
I really enjoyed using TMCache although it seems to not be maintained anymore. It has in memory and disk cache and a very good performance.

EGOPhotoViewer - Memory warning with many pictures iOS

I have a problem with the memory managment in EGOPhotoViewer. I get a memory warning after scroll about 50 pictures. In total, they have about 270 of them, each weighing approximately 100 kb and is different from others. I tried to resolve this problem by https://github.com/enormego/PhotoViewer/issues/6, but nothing helped.
Please help me, Pawel
//----- EDIT
Add further that all objects are properly released. In my opinion the problem is not removing images from the cache, but I don't know how to bite it...
You're loading all of them in the memory of course, and this is bad.
You need to use something like Core Data\NSIncrementalStore (Explanation of NSIncrementalStore in plain english).
Another option is to use the NSUserDefaults, but this is a bad practice, as it is for storing user data only, but it gets the job done + it caches its data, for fast retrieval.
Need more help? I'm here ;D

load 5MB of images crashed iPad

I need to load 5MB of HD images (for iPad) before my game starts up. It crashes somewhere in the loading progress. Well, to confirm it was the 5MB problem, I then tried to load 2.5MB of LD images (iPhone quality) instead. It ran OK, no crashes.
Does it mean that I can't reserve 5MB or more memory? There should be a way to do it.
This happens more frequently when more apps pending in the background. And it doesn't crash if I run my game immediately after a clean reboot. Therefore, it must be a memory problem crashing my game.
Any idea how I can handle this?
5MB of compressed image data can easily explose to many (4x-10x) the memory requirements to have them uncompressed.
Any idea how I can handle this?
Use Apple's Instruments and look at memory usage.
Next ensure iOS itself is not caching images (look at the API you're using and their documentation, some will cache, others won't).
Then look if you can dispose of the image earlier. Images can be quite big (and a lot of memory for them is internal to iOS, which is why using Instruments will give you a better picture than MonoTouch's own HeapShot profiler) so disposing it manually (instead of waiting for the GC is generally a good idea).
Also look if you can delay load some images (or at least their decompressed versions), e.g. after the first one(s) are disposed.

Resources