나는 30 셀로 구성된 collectionview로 구성된 앱을 가지고있다. 그 셀은 이미지와 레이블로 구성됩니다. 내 문제는, 내가 이미지를로드 할 때 내 메모리 사용량이 87Mb가된다는 것입니다. 그러나 그 이미지를 설정하지 않으면 메모리 사용량이 30MB 밖에되지 않습니다.컬렉션보기에서 메모리 사용을 줄이는 방법은 무엇입니까?
Moa을 사용하여 이미지를 비동기 적으로로드합니다. 여기
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
}
}
}
그리고 내 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
}
}
이미지를 다운로드하여 "압축"어떤 방법이 있나요 : 그리고 여기 내 휴대 초기화는? 아니면 내가 잘못하고 있니? Pls 알려주세요. 이 시점에서 1 주일간 붙어 있습니다.
참고 : 내 애플 리케이션과 같이 콜렉션 뷰가있는 일부 애플 리케이션을위한 표준 메모리 사용량은 얼마나됩니까? 30Mb가 "높음"에 속해 있습니까? 나는 메모리 관리에 초보자입니다.
정말 고마워요.
이 라이브러리 ** Moa ** 당신이 언급하는 경우에 따라 달라집니다 기본적으로 그리고 얼마나 많은 메모리 캐시. 프로젝트 페이지에서 먼저 이것에 대해 알아야합니다. 그럼에도 불구하고 이미지를 다운로드하기 위해 라이브러리를 사용하는 이유와, Kingfisher와 같이 셀의 재사용 성을 처리하는 라이브러리를 사용하려는 경우 어떻게해야하는지 모르겠습니다. –
이미지의 크기는 무엇이며 셀의 이미지 뷰의 크기는 무엇입니까? 이미지는 이미지 뷰 크기 (물론 시간, 장치의 '스케일')보다 커야합니다. 크기가 더 큰 경우 일치시킬 이미지 크기를 조정할 수 있습니다. – Rob
참고로 이미지에 필요한 런타임 메모리는 일반적으로 4 x'width' x'height' (이미지보기의 크기에 관계없이 이미지의 크기)입니다. – Rob