Autosaving NSDocument memory leak with NSWindow and NSToolbar - NSDocumentTitlebarPopoverViewController leaks

I think I have found a Cocoa memory leak that is resulting in my NSDocuments being retained after they have been closed by the user. I am posting here to see if anyone else has encountered this, and if so, what solutions might be available.

Essentially, when you have an Autosaving NSDocument that opens an NSWindow containing an NSToolbar the default 'Unified' toolbar style places the Document title to the left of the Toolbar. When the titlebar is laid out like this, there is a clickable area to the right of the title. If the user clicks in this area a log error appears that reads '[Document] Popover failed to show'

This seems harmless enough, but in actual fact a memory leak has occurred with the 'NSDocumentTitlebarPopoverViewController' that has failed to show. This View Controller is retained, and unfortunately it contains a strong reference to the NSDocument. So the entire NSDocument instance is also retained.

Here is a screenshot of the clickable area:

Here is a link to a minimum reproducible example, hosted on GitHub. It is just a template Document Based App with an added Toolbar and a print statement in the Deinit of the Document so you can see if it deinits successfully.

Searching online for the '[Document] Popover failed to show' log message doesn't yield any results, nor does searching for the leaking View Controller class name ('NSDocumentTitlebarPopoverViewController').

Autosaving NSDocument memory leak with NSWindow and NSToolbar - NSDocumentTitlebarPopoverViewController leaks
 
 
Q