ios - UITableView with many images high memory usage -


hi using mkmapsnapshotter generate map images , cache them using sdwebimage. map images displayed in each uitableview cell.

the problem i'm having 30 uitableview cells memory used 130 mb, if don't use map images memory used 25 mb, , using map images without caching(as in generating map image every time cell displayed) memory used 50 mb.

how can reduce memory usage? or how can store images take less memory space? appreciated. code have below.

at top of class:

var imagecache: sdimagecache! var mysnapoptions: mkmapsnapshotoptions! let regionradius: cllocationdistance = 300 let queue = dispatch_get_global_queue(dispatch_queue_priority_high, 0) 

in viewdidload():

imagecache = sdimagecache(namespace: "mynamespace") mysnapoptions = mkmapsnapshotoptions() mysnapoptions.scale = uiscreen.mainscreen().scale 

and in cellforrow:

override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath, object: pfobject?) -> tableviewcell? {     let cell = tableview.dequeuereusablecellwithidentifier("cell", forindexpath: indexpath) as! tableviewcell      if let post = object {         cell.mapimageview.image = uiimage(named: "mapplaceholder")          let temploc = post["location"] as! pfgeopoint         let loc = cllocation(latitude: temploc.latitude, longitude: temploc.longitude)          imagecache.querydiskcacheforkey(post.objectid, done: {(image: uiimage?, cachetype: sdimagecachetype!) in             if let cachedimage = image {                 cell.mapimageview.image = cachedimage             }else {                 cell.mappinimageview.hidden = true                 cell.mapactivityindicator.startanimating()                  dispatch_async(self.queue) { () -> void in                     self.mysnapoptions.region = mkcoordinateregionmakewithdistance(loc.coordinate,                         self.regionradius * 2.0, self.regionradius * 2.0)                     self.mysnapoptions.size = (cell.mapimageview.image?.size)!                      mkmapsnapshotter(options: self.mysnapoptions).startwithcompletionhandler { snapshot, error in                         guard let snapshot = snapshot else {                             print("snapshot error: \(error)")                             return                         }                         self.imagecache.storeimage(snapshot.image, forkey: post.objectid, todisk: true)                         dispatch_async(dispatch_get_main_queue(), {                             cell.mapactivityindicator.stopanimating()                             cell.mapimageview.image = snapshot.image                             cell.mappinimageview.hidden = false                         })                     }                      //                 }             }         })       }     return cell } 

i ended using different caching framework. fastimagecache, allowed me achieve desired results great scrolling performance, , low memory usage, images not stored in memory rather on disk (this how fastimagecache works).


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -