ios - How to reduce memory usage in collection view? -
i have app consist of collectionview 30 cell. cell consist of image , label. problem is, when load image memory use going 87 mb. if didn't set image, memory use 30 mb.
i using moa load image asynchronously. , here cell init:
import uikit import moa class productlistitemcell: uicollectionviewcell { @iboutlet var imgproductitem: uiimageview! @iboutlet var titlleproductlist: uilabel! @iboutlet var priceproductlist: uilabel! @iboutlet var boldpriceproductlist: uilabel! func updatecontent(product: item) { // if let imgurl = product.picurl { // self.imgproductitem.moa.url = "http:\(imgurl)" // } if let title = product.title { self.titlleproductlist.text = title } if let price = product.pricetag { self.priceproductlist.setstrikethrough(price) } if let boldprice = product.price { self.boldpriceproductlist.text = boldprice } } }
and here cellforitematindexpath
func collectionview(collectionview: uicollectionview, cellforitematindexpath indexpath: nsindexpath) -> uicollectionviewcell { if collectionview == myitemscollectionview { let cell = collectionview.dequeuereusablecellwithreuseidentifier("firstcell", forindexpath: indexpath) as! mycollectionviewcell cell.updatecontent(self.myitems.items[indexpath.item]) return cell } else { let cell = collectionview.dequeuereusablecellwithreuseidentifier("otherscell", forindexpath: indexpath) as! mycollectionviewcell cell.updatecontent(others[indexpath.section].items[indexpath.item]) return cell } }
is there way download image , "compress" it? or doing wrong? pls let me know. been stuck @ point weeks.
note: how many memory use standard apps collectionview apps? 30mb belongs "high"? newbie in memory management.
thank much.
yes, use instrument check memory leak , memory increase caused image load correct. had problem before. did use image caching library such sdwebimage , solve problem it's require data first time fetch
Comments
Post a Comment