discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSWindow retains cycle


From: Alexander Malmberg
Subject: NSWindow retains cycle
Date: Mon, 18 Feb 2002 18:02:27 +0100

Hi,

Another one, in NSWindow this time. The reason I wasn't seeing the
previous bug every time was that an NSWindow will retain itself in
NSWindow -sendEvent: when handling NSKeyDown if _firstResponder==self.
In my case the key down went to a button that closed the window, so if
the key up event arrived after the window disappeared (eg. if you hold
down the key) the window won't get the event and it won't release
itself.

Anyway, I think (it fixed the problem, at least) the way to fix this is
to not retain/release _originalResponder if it's set to self. I've
included a patch that does this.

[Incidentally, I've written a (really crude and ugly and i386-specific)
retain/release/autorelease tracker that I've used when debugging it.
Basically, it dumps a log of all retains etc. for objects you're
interested in, and after it's done it's easy (but boring; it could be
mostly automated) to sit down and match retains to releases and figure
out where the problem is. If there's any interest I could upload the
source somewhere. However, it is _really_ ugly.]

- Alexander Malmberg

Index: NSWindow.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/gui/Source/NSWindow.m,v
retrieving revision 1.217
diff -u -r1.217 NSWindow.m
--- NSWindow.m  18 Feb 2002 12:10:06 -0000      1.217
+++ NSWindow.m  18 Feb 2002 16:46:56 -0000
@@ -614,7 +614,8 @@
   TEST_RELEASE(_windowTitle);
   TEST_RELEASE(_rectsBeingDrawn);
   TEST_RELEASE(_initialFirstResponder);
-  TEST_RELEASE(_originalResponder);
+  if (_originalResponder != self)
+    TEST_RELEASE(_originalResponder);
   TEST_RELEASE(_defaultButtonCell);
 
   /*
@@ -2780,7 +2781,10 @@
         * Save the first responder so that the key up goes to it and
not a
         * possible new first responder.
         */
-       ASSIGN(_originalResponder, _firstResponder);
+       if (_firstResponder == self)
+         _originalResponder = self;
+       else
+         ASSIGN(_originalResponder, _firstResponder);
        [_firstResponder keyDown: theEvent];
        break;
 
@@ -2790,7 +2794,10 @@
           */
          if (_originalResponder)
            [_originalResponder keyUp: theEvent];
-         DESTROY(_originalResponder);
+         if (_originalResponder == self)
+           _originalResponder = nil;
+         else
+           DESTROY(_originalResponder);
          break;
 
       case NSFlagsChanged:                               // Flags
changed



reply via email to

[Prev in Thread] Current Thread [Next in Thread]