Fix retain cycle in timestamp updating code

The timestamp update work item shouldn't retain a reference to the cell.
It can be unowned because when the cell is deinit'd, the work item will
be cancelled.
This commit is contained in:
Shadowfacts 2020-01-19 23:10:52 -05:00
parent 32e89f2c16
commit 8eb6f6f573
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
4 changed files with 21 additions and 4 deletions

View File

@ -27,6 +27,10 @@ class ActionNotificationGroupTableViewCell: UITableViewCell {
var authorAvatarURL: URL?
var updateTimestampWorkItem: DispatchWorkItem?
deinit {
updateTimestampWorkItem?.cancel()
}
override func awakeFromNib() {
super.awakeFromNib()
@ -110,7 +114,9 @@ class ActionNotificationGroupTableViewCell: UITableViewCell {
delay = nil
}
if let delay = delay {
updateTimestampWorkItem = DispatchWorkItem(block: self.updateTimestamp)
updateTimestampWorkItem = DispatchWorkItem { [unowned self] in
self.updateTimestamp()
}
DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: updateTimestampWorkItem!)
} else {
updateTimestampWorkItem = nil

View File

@ -22,6 +22,10 @@ class FollowNotificationGroupTableViewCell: UITableViewCell {
var updateTimestampWorkItem: DispatchWorkItem?
deinit {
updateTimestampWorkItem?.cancel()
}
override func awakeFromNib() {
super.awakeFromNib()
@ -98,7 +102,7 @@ class FollowNotificationGroupTableViewCell: UITableViewCell {
delay = nil
}
if let delay = delay {
updateTimestampWorkItem = DispatchWorkItem {
updateTimestampWorkItem = DispatchWorkItem { [unowned self] in
self.updateTimestamp()
}
DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: updateTimestampWorkItem!)

View File

@ -27,6 +27,10 @@ class FollowRequestNotificationTableViewCell: UITableViewCell {
var updateTimestampWorkItem: DispatchWorkItem?
deinit {
updateTimestampWorkItem?.cancel()
}
override func awakeFromNib() {
super.awakeFromNib()
@ -72,7 +76,9 @@ class FollowRequestNotificationTableViewCell: UITableViewCell {
delay = nil
}
if let delay = delay {
updateTimestampWorkItem = DispatchWorkItem(block: self.updateTimestamp)
updateTimestampWorkItem = DispatchWorkItem { [unowned self] in
self.updateTimestamp()
}
DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: updateTimestampWorkItem!)
} else {
updateTimestampWorkItem = nil

View File

@ -34,6 +34,7 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell {
deinit {
rebloggerAccountUpdater?.cancel()
updateTimestampWorkItem?.cancel()
}
override func awakeFromNib() {
@ -109,7 +110,7 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell {
delay = nil
}
if let delay = delay {
updateTimestampWorkItem = DispatchWorkItem {
updateTimestampWorkItem = DispatchWorkItem { [unowned self] in
self.updateTimestamp()
}
DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: updateTimestampWorkItem!)