NSTableViewDiffableDataSource causes a strong retain cycle

Originator:AlexanderMomchilov
Number:rdar://FB8959397 Date Originated:2021 Jan 2
Status:Open Resolved:
Product:AppKit Product Version:macOS 11.1 (20C69)
Classification: Reproducible:Yes
 
This minimal code causes a retain cycle, even when the `tableView` and `dataSource` variables go out of scope

```swift
let tableView = NSTableView()
let dataSource = NSTableViewDiffableDataSource<String, String>(
	tableView: tableView) { (tableView, column, i, model) -> NSView in
	fatalError(“Stub for compilation, this closure will never be called”)
}
```

It appears that `NSTableViewDiffableDataSource` captures its `wrapper` field (of type NSTableViewDiffableDataSourceWrapper) strongly, which in turn captures its `dataSource` field strongly.

See the attached project for a simple demo.

Comments

"Potential fix identified - For a future OS update"

By AlexanderMomchilov at April 21, 2021, 2:31 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!