In my rss feeder like application, I have an array which contains NewsItems, and each item are responsible to request its image from the web asynchronously (By using ASCHTTPRequest library and NSOperationQueue method)
I would like to add a refresh function to my rss feeder. My attempt is to recreate a new array again (and dealloc all the old NewsItems) and repeat the request process.
However, it would result in a crash with EXC_BAD_ACCESS error if I refresh the content BEFORE all NewsItems get their images. (Since the old items are dealloc and there is callback to those items through delegate..)
How should I solve this problem in a better way? Does it mean that I cannot simply dealloc all my old items without checking if each of them is already done its request?
Sorry if I cannot describe my question clearly. Looking forward to your help Thanks!
You’ll have to keep a track of all your current HTTP Requests. And when you wish to refresh, cancel all your requests, and then recreate your new array. This way your asynchronous requests won’t try to update your deallocated images.