Question

I have implemented a list where a number of large images are being loaded asynchronously. I am using an instance of NSCache to store these UIImage files. As I scroll down, I load more and more images. I set this up and was profiling the app for allocations, and I noticed that the cache does not seem to be releasing any memory. The "Live Bytes" field has gone up to 165 MB and counting. What is the limit at which the cache starts freeing memory? Or do I have to set it myself?

Was it helpful?

Solution

You need to dictate the caching limits with calls to [NSCache setCountLimit:] and [NSCache setTotalCostLimit:].

See [NSCache setObject:forKey:cost:] to allocate a cost for each entry.

OTHER TIPS

You should use

- (void)setCountLimit:(NSUInteger)lim;

to set the NSCache limit

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top