Rameez Hussain
Rameez Hussain

Reputation: 6764

When does NSCache release the caches objects?

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?

Upvotes: 3

Views: 3450

Answers (2)

rakmoh
rakmoh

Reputation: 2963

You should use

- (void)setCountLimit:(NSUInteger)lim;

to set the NSCache limit

Upvotes: 0

trojanfoe
trojanfoe

Reputation: 122421

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.

Upvotes: 3

Related Questions