How to clear NSURLCache when downloading images using NSURLConnection

[]
1
2
3
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil]; 
[NSURLCache setSharedURLCache:sharedCache]; 
[sharedCache release];


I didn't know why the memory was so high in my iOS application when using NSURLConnection to download multiple images in the background. I found out that the image data was being saved to NSURLCache and was never released. This line of code clears the NSURLCache and cleaned up a lot of memory in my iOS application. I hope this helps someone else out there!


See this post on Forrst

Comments