REGRESSION (r103859): WKViews leak
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 8 Jan 2012 21:44:52 +0000 (21:44 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 8 Jan 2012 21:44:52 +0000 (21:44 +0000)
https://bugs.webkit.org/show_bug.cgi?id=75805

The flags changed event monitor added in r103859 was retaining the WKView (as it references
self in the handler block), causing it to leak.

* UIProcess/API/mac/WKView.mm:
(-[WKView dealloc]): Moved call to remove the flags changed event monitor from here...
(-[WKView viewDidMoveToWindow]): ...to here. Moved call to add the flags changed event
monitor to here from...
(-[WKView initWithFrame:contextRef:pageGroupRef:]): ...here.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@104409 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/mac/WKView.mm

index 04730f4d5d9e5af6425d7bb7ab416dc45d3e6462..55d184acc784cf45220a66dc76fd2c32d22786c9 100644 (file)
@@ -1,3 +1,17 @@
+2012-01-08  Dan Bernstein  <mitz@apple.com>
+
+        REGRESSION (r103859): WKViews leak
+        https://bugs.webkit.org/show_bug.cgi?id=75805
+
+        The flags changed event monitor added in r103859 was retaining the WKView (as it references
+        self in the handler block), causing it to leak.
+
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView dealloc]): Moved call to remove the flags changed event monitor from here...
+        (-[WKView viewDidMoveToWindow]): ...to here. Moved call to add the flags changed event
+        monitor to here from...
+        (-[WKView initWithFrame:contextRef:pageGroupRef:]): ...here.
+
 2012-01-06  Mark Rowe  <mrowe@apple.com>
 
         REGRESSION (WebKit2): Save as PDF no longer generates links to URLs
index 0bb1743372c795a0798661d6976638e4a368ab17..1e2509ba697e5da91badb59cc54042e7ec873355 100644 (file)
@@ -225,7 +225,6 @@ struct WKViewInterpretKeyEventsParameters {
 - (void)dealloc
 {
     _data->_page->close();
-    [NSEvent removeMonitor:_data->_flagsChangedEventMonitor];
 
     ASSERT(!_data->_inSecureInputState);
 
@@ -1823,12 +1822,20 @@ static NSString * const backingPropertyOldScaleFactorKey = @"NSBackingPropertyOl
         _data->_page->viewStateDidChange(WebPageProxy::ViewIsVisible | WebPageProxy::ViewIsInWindow);
         [self _updateWindowVisibility];
         [self _updateWindowAndViewFrames];
-        
-        [self _accessibilityRegisterUIProcessTokens];            
+
+        _data->_flagsChangedEventMonitor = [NSEvent addLocalMonitorForEventsMatchingMask:NSFlagsChangedMask handler:^(NSEvent *flagsChangedEvent) {
+            [self _postFakeMouseMovedEventForFlagsChangedEvent:flagsChangedEvent];
+            return flagsChangedEvent;
+        }];
+
+        [self _accessibilityRegisterUIProcessTokens];
     } else {
         _data->_page->viewStateDidChange(WebPageProxy::ViewIsVisible);
         _data->_page->viewStateDidChange(WebPageProxy::ViewWindowIsActive | WebPageProxy::ViewIsInWindow);
 
+        [NSEvent removeMonitor:_data->_flagsChangedEventMonitor];
+        _data->_flagsChangedEventMonitor = nil;
+
 #if ENABLE(GESTURE_EVENTS)
         if (_data->_endGestureMonitor) {
             [NSEvent removeMonitor:_data->_endGestureMonitor];
@@ -2703,10 +2710,6 @@ static void drawPageBackground(CGContextRef context, WebPageProxy* page, const I
 #endif
     _data->_mouseDownEvent = nil;
     _data->_ignoringMouseDraggedEvents = NO;
-    _data->_flagsChangedEventMonitor = [NSEvent addLocalMonitorForEventsMatchingMask:NSFlagsChangedMask handler:^(NSEvent *flagsChangedEvent) {
-        [self _postFakeMouseMovedEventForFlagsChangedEvent:flagsChangedEvent];
-        return flagsChangedEvent;
-    }];
 
     [self _registerDraggedTypes];