Reputation: 45
i have tableView
with 12 images. 1 for each row. The image size is 536 x x536 px (and 804 x 804 for @3x) all in JPG format with about 250kb file size. When i use Simulator, the memory reach 40MB for that tableView
only. Yes, i've used dequeueReusableCellWithIdentifier
. here is the screenshot :
is it normal? or how i can improve it? because i use UIImage(named:....)
so it's cached.
I haven't try to use real device, still waiting for my credit card.. :)
here my code for cellForRowAtIndexPath
:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let kolom = tableView.dequeueReusableCellWithIdentifier("portraitkolom", forIndexPath: indexPath) as portraitdetailTableViewCell
let portrait = portraits[indexPath.row]
kolom.portraitdetailgambar.image = UIImage(named: portrait.thumbImage)
kolom.portraitdetailgambar.layer.shadowColor = UIColor(red: 200.0/255.0, green: 200.0/255.0, blue: 200.0/255.0, alpha: 1.0).CGColor
kolom.portraitdetailgambar.layer.shadowOffset = CGSizeMake(0, 2)
kolom.portraitdetailgambar.layer.shadowRadius = 0
kolom.portraitdetailgambar.layer.shadowOpacity = 1.0
return kolom
}
UPDATE :
using UIImage(contentsOfFile:)
seems a bit reducing memory usage.
here is the screenshot :
updated code :
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let kolom = tableView.dequeueReusableCellWithIdentifier("portraitkolom", forIndexPath: indexPath) as portraitdetailTableViewCell
let portrait = portraits[indexPath.row]
let paths = NSBundle.mainBundle().pathForResource(portrait.thumbImage, ofType: "jpg", inDirectory: "portraitthumb")
kolom.portraitdetailgambar.image = UIImage(contentsOfFile: paths!)
kolom.portraitdetailgambar.layer.shadowColor = UIColor(red: 200.0/255.0, green: 200.0/255.0, blue: 200.0/255.0, alpha: 1.0).CGColor
kolom.portraitdetailgambar.layer.shadowOffset = CGSizeMake(0, 2)
kolom.portraitdetailgambar.layer.shadowRadius = 0
kolom.portraitdetailgambar.layer.shadowOpacity = 1.0
return kolom
}
but it still 32MB.. is it normal?
and it look like UIImage(contentsOfFile:)
doesn't detect @2x or @3x images (case sensitive?).. so i rename my images to be someimage.jpg (previously [email protected]). Is that correct?
thanks.
Upvotes: 0
Views: 2141
Reputation: 71854
some tips for you if u want image in your cell:
reference from HERE.
Upvotes: 3
Reputation: 96
Just for performance improvement. do the following steps
For details Info check this link: http://www.jorambarrez.be/blog/2012/04/19/ios-imagenamed-vs-imagewithcontentsoffile/
Upvotes: 0