fix: compose scene memory leaking issue

This commit is contained in:
CMK 2021-05-28 15:55:58 +08:00
parent 252c58ad2c
commit 90d8de1625
2 changed files with 19 additions and 8 deletions

View File

@ -101,7 +101,8 @@ extension ComposeStatusSection {
cell.composeContent cell.composeContent
.removeDuplicates() .removeDuplicates()
.receive(on: DispatchQueue.main) .receive(on: DispatchQueue.main)
.sink { text in .sink { [weak collectionView] text in
guard let collectionView = collectionView else { return }
// self size input cell // self size input cell
// needs restore content offset to resolve issue #83 // needs restore content offset to resolve issue #83
let oldContentOffset = collectionView.contentOffset let oldContentOffset = collectionView.contentOffset
@ -115,7 +116,9 @@ extension ComposeStatusSection {
.store(in: &cell.disposeBag) .store(in: &cell.disposeBag)
attribute.isContentWarningComposing attribute.isContentWarningComposing
.receive(on: DispatchQueue.main) .receive(on: DispatchQueue.main)
.sink { isContentWarningComposing in .sink { [weak cell, weak collectionView] isContentWarningComposing in
guard let cell = cell else { return }
guard let collectionView = collectionView else { return }
// self size input cell // self size input cell
collectionView.collectionViewLayout.invalidateLayout() collectionView.collectionViewLayout.invalidateLayout()
cell.statusContentWarningEditorView.containerView.isHidden = !isContentWarningComposing cell.statusContentWarningEditorView.containerView.isHidden = !isContentWarningComposing
@ -130,7 +133,8 @@ extension ComposeStatusSection {
cell.contentWarningContent cell.contentWarningContent
.removeDuplicates() .removeDuplicates()
.receive(on: DispatchQueue.main) .receive(on: DispatchQueue.main)
.sink { text in .sink { [weak collectionView] text in
guard let collectionView = collectionView else { return }
// self size input cell // self size input cell
collectionView.collectionViewLayout.invalidateLayout() collectionView.collectionViewLayout.invalidateLayout()
// bind input data // bind input data
@ -145,9 +149,10 @@ extension ComposeStatusSection {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: ComposeStatusAttachmentCollectionViewCell.self), for: indexPath) as! ComposeStatusAttachmentCollectionViewCell let cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: ComposeStatusAttachmentCollectionViewCell.self), for: indexPath) as! ComposeStatusAttachmentCollectionViewCell
cell.attachmentContainerView.descriptionTextView.text = attachmentService.description.value cell.attachmentContainerView.descriptionTextView.text = attachmentService.description.value
cell.delegate = composeStatusAttachmentTableViewCellDelegate cell.delegate = composeStatusAttachmentTableViewCellDelegate
attachmentService.imageData attachmentService.data
.receive(on: DispatchQueue.main) .receive(on: DispatchQueue.main)
.sink { imageData in .sink { [weak cell] imageData in
guard let cell = cell else { return }
let size = cell.attachmentContainerView.previewImageView.frame.size != .zero ? cell.attachmentContainerView.previewImageView.frame.size : CGSize(width: 1, height: 1) let size = cell.attachmentContainerView.previewImageView.frame.size != .zero ? cell.attachmentContainerView.previewImageView.frame.size : CGSize(width: 1, height: 1)
guard let imageData = imageData, guard let imageData = imageData,
let image = UIImage(data: imageData) else { let image = UIImage(data: imageData) else {
@ -171,7 +176,8 @@ extension ComposeStatusSection {
attachmentService.error.eraseToAnyPublisher() attachmentService.error.eraseToAnyPublisher()
) )
.receive(on: DispatchQueue.main) .receive(on: DispatchQueue.main)
.sink { uploadState, error in .sink { [weak cell] uploadState, error in
guard let cell = cell else { return }
cell.attachmentContainerView.emptyStateView.isHidden = error == nil cell.attachmentContainerView.emptyStateView.isHidden = error == nil
cell.attachmentContainerView.descriptionBackgroundView.isHidden = error != nil cell.attachmentContainerView.descriptionBackgroundView.isHidden = error != nil
if let _ = error { if let _ = error {
@ -220,7 +226,8 @@ extension ComposeStatusSection {
cell.durationButton.setTitle(L10n.Scene.Compose.Poll.durationTime(attribute.expiresOption.value.title), for: .normal) cell.durationButton.setTitle(L10n.Scene.Compose.Poll.durationTime(attribute.expiresOption.value.title), for: .normal)
attribute.expiresOption attribute.expiresOption
.receive(on: DispatchQueue.main) .receive(on: DispatchQueue.main)
.sink { expiresOption in .sink { [weak cell] expiresOption in
guard let cell = cell else { return }
cell.durationButton.setTitle(L10n.Scene.Compose.Poll.durationTime(expiresOption.title), for: .normal) cell.durationButton.setTitle(L10n.Scene.Compose.Poll.durationTime(expiresOption.title), for: .normal)
} }
.store(in: &cell.disposeBag) .store(in: &cell.disposeBag)

View File

@ -57,6 +57,10 @@ final class ComposeStatusAttachmentCollectionViewCell: UICollectionViewCell {
_init() _init()
} }
deinit {
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
}
} }
extension ComposeStatusAttachmentCollectionViewCell { extension ComposeStatusAttachmentCollectionViewCell {