iOS development: UITableView loading multiple photos causes memory to rise

Source: Internet
Author: User

Recently in a File Management page, there are a lot of features, there is a thumbnail download (socket), there is file Download (HTTP).


Say the thumbnail download this piece, my uitableview a cell to load four thumbnails, IPhone5S's screen can load 8 rows. This is probably the way the UI is laid out. (in addition, thumbnails need a single download)


Just started to go to the file management interface, memory consumption of 20 m, as thumbnails continue to download in the presence of rising, I constantly pull up, memory value is rising. Reach a certain value app appears to flash back. It's about 300 m. What causes it?


Look first:



I wrote this: Create an object that has a property of UIImage. Objects are stored inside the array. There are about 800 photos.


When the thumbnail is not downloaded, I'm loading a default image. When the thumbnail is downloaded, I assign the downloaded thumbnail to the UIImage property of the corresponding object.


The cell is reused, so there should be no problem. But memory is constantly rising, and is not moving when the memory does not rise, up and down sliding uitableview, memory is rising.


I've been thinking about cell reuse, how does memory keep rising? The problem is not caused by the cell, but by the UIImage property of the object I said above.


Think about it, thumbnails are constantly downloaded, downloaded thumbnails are assigned to the object's UIImage property, and the object is in the array, it is conceivable that more than 800 thumbnails constantly download memory certainly rose.


So, I removed the object's UIImage property, the downloaded photos through the Egocache cache, load the cell on the UIImage, directly from the cache to take out.


The code is as follows:


[[Egocache Globalcache] setimage:image forkey:[nsstring stringwithformat:@ "Egoimageloader-%lu", (unsigned long) [[ Fmobject.path description] [] withtimeoutinterval:cacheingtime];


Run again and look at this piece of memory:



Sure enough, the problem was solved. It seems to be prudent to add uiimage attributes to the object later!


There are questions you can join Swift Learning Exchange Group:


QQ Group: 303868520


or follow my public number: iOS Development: Iosdevtip


iOS development: UITableView loading multiple photos causes memory to rise

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.