Using the performSelectorInBackground function to load a UITableViewCell image in the background, performance

I have a way to load images for a UITableViewCell in the background. I am using performSelectorInBackground. The problem is that these streams complete and load images, even if they no longer appear on the screen. This can be taxed on resources, especially when using scroll quickly and creating multiple cells. Images are quite small and are loaded from disk (sqlite db), not from the URL.

I put the code in a cell to check if this is the last displayed cell, and I do not upload the image if it is not. This works, but it still creates threads, even if the β€œexpensive” job of loading an image from disk is not performed, unless it is the very last cell.

The question is, what is the best way to handle this? Should I kill existing threads every time a UITableViewCell is reused? How can I kill streams called by performSelectorInBackground?

Any other suggestions on how to handle this are welcome.

+4
source share
2 answers

Have you viewed EGOImageView ?

+5
source

You can simply upload one image at a time. You can still do this on a thread, but serialize the loads so as not to overload the system.

You can add visible cells to the array when they become visible, when the cells become invisible, you can remove them from the list (or just check to see if they are visible at a convenient time for you). You can also try deferring the download for a short period of time to avoid loading the image, which simply scrolls. The thread will push the first item from the list and load it, and then load the next load.

For threading technologies, you can take a look at Operation Queues or create a dedicated thread using NSThread . Concurrency Programming Guide gives a good overview. Although there is nothing wrong with the method you use.

Exchange between threads will also require some form of locking to avoid simultaneous access.

0
source

All Articles