UICollectionView加载Emoji使用UILabel时内存持续增长且无法回收的问题
问题描述
我尝试搭建如下样式的表情列表:
以下是我编写的Cell代码:
class EmojiCell: UICollectionViewCell { override init(frame: CGRect) { super.init(frame: frame) makeUI() } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func prepareForReuse() { super.prepareForReuse() emojiLabel.text = nil } lazy var emojiLabel: UILabel = { let view = UILabel() view.font = UIFont(name: "Apple color emoji", size: 30) view.textAlignment = .center return view }() private func makeUI() { contentView.addSubview(emojiLabel) emojiLabel.translatesAutoresizingMaskIntoConstraints = false emojiLabel.topAnchor.constraint(equalTo: contentView.topAnchor).isActive = true emojiLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor).isActive = true emojiLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor).isActive = true emojiLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor).isActive = true } func setEmoji(emoji: String) { emojiLabel.text = emoji } }
遇到的问题
- 滚动
UICollectionView时,内存持续增长 - 关闭该页面后,已占用的内存没有被回收
- 检测发现存在
CFString类型的内存泄漏
希望能得到这个问题的解决思路,非常感谢。
内容的提问来源于stack exchange,提问作者wanbo
相关产品推荐
相关产品推荐

