Bug 1523944: Fix shutdown leak related to macOS TouchBar support. r=mstange, a=lizzard
authorStephen A Pohl <spohl.mozilla.bugs@gmail.com>
Wed, 13 Feb 2019 14:16:39 -0500
changeset 516005 e0e4b872648840352e81400e823a8b146f8780e3
parent 516004 c341768d99a4889091c5322e84ef5382302d3b7f
child 516006 05f992aafb09ea89c1681eab913e1bc3b823452c
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange, lizzard
bugs1523944
milestone66.0
Bug 1523944: Fix shutdown leak related to macOS TouchBar support. r=mstange, a=lizzard
widget/cocoa/nsCocoaWindow.h
widget/cocoa/nsCocoaWindow.mm
widget/cocoa/nsTouchBar.h
widget/cocoa/nsTouchBar.mm
--- a/widget/cocoa/nsCocoaWindow.h
+++ b/widget/cocoa/nsCocoaWindow.h
@@ -81,16 +81,18 @@ typedef struct _nsCocoaWindowList {
 
 - (void)disableSetNeedsDisplay;
 - (void)enableSetNeedsDisplay;
 
 - (NSRect)getAndResetNativeDirtyRect;
 
 - (void)setUseMenuStyle:(BOOL)aValue;
 
+- (void)releaseJSObjects;
+
 @end
 
 @interface NSWindow (Undocumented)
 
 // If a window has been explicitly removed from the "window cache" (to
 // deactivate it), it's sometimes necessary to "reset" it to reactivate it
 // (and put it back in the "window cache").  One way to do this, which Apple
 // often uses, is to set the "window number" to '-1' and then back to its
--- a/widget/cocoa/nsCocoaWindow.mm
+++ b/widget/cocoa/nsCocoaWindow.mm
@@ -160,16 +160,17 @@ nsCocoaWindow::nsCocoaWindow()
   }
 }
 
 void nsCocoaWindow::DestroyNativeWindow() {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
   if (!mWindow) return;
 
+  [mWindow releaseJSObjects];
   // We want to unhook the delegate here because we don't want events
   // sent to it after this object has been destroyed.
   [mWindow setDelegate:nil];
   [mWindow close];
   mWindow = nil;
   [mDelegate autorelease];
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
@@ -3116,16 +3117,20 @@ static const NSString* kStateCollectionB
     retval = [NSArray arrayWithArray:holder];
   }
 
   return retval;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
 }
 
+- (void)releaseJSObjects {
+  [mTouchBar releaseJSObjects];
+}
+
 @end
 
 // This class allows us to exercise control over the window's title bar. This
 // allows for a "unified toolbar" look without having to extend the content
 // area into the title bar.
 //
 // Drawing the unified gradient in the titlebar and the toolbar works like this:
 // 1) In the style sheet we set the toolbar's -moz-appearance to toolbar.
--- a/widget/cocoa/nsTouchBar.h
+++ b/widget/cocoa/nsTouchBar.h
@@ -168,11 +168,13 @@ typedef NSString* NSTouchBarItemIdentifi
                             sharingServicesForItems:(NSArray*)aItems
                             proposedSharingServices:(NSArray<NSSharingService*>*)aProposedServices;
 
 /**
  * Retrieves TouchBarInput icons.
  */
 + (NSImage*)getTouchBarIconNamed:(NSString*)aImageName;
 
+- (void)releaseJSObjects;
+
 @end  // nsTouchBar
 
 #endif  // nsTouchBar_h_
--- a/widget/cocoa/nsTouchBar.mm
+++ b/widget/cocoa/nsTouchBar.mm
@@ -187,16 +187,20 @@ static char sIdentifierAssociationKey;
   if (!input) {
     return;
   }
 
   nsCOMPtr<nsITouchBarInputCallback> callback = [input callback];
   callback->OnCommand();
 }
 
+- (void)releaseJSObjects {
+  mTouchBarHelper = nil;
+}
+
 #pragma mark - TouchBar Utilities
 
 + (NSImage*)getTouchBarIconNamed:(NSString*)aImageName {
   nsCOMPtr<nsIFile> resDir;
   nsAutoCString resPath;
   NSString* pathToImage;
 
   nsresult rv = NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(resDir));