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?
Asked
Active
Viewed 3,259 times
3

David Rönnqvist
- 56,267
- 18
- 167
- 205

Rameez Hussain
- 6,414
- 10
- 56
- 85
2 Answers
3
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.

trojanfoe
- 120,358
- 21
- 212
- 242
-
So the total cost limit is the value in bytes is it? – Rameez Hussain Sep 19 '13 at 16:15
-
@RameezHussain No, I've just updated my answer; it's whatever units you care to imagine. – trojanfoe Sep 19 '13 at 16:16