Re: Disappointed by GNUstep

Sergei Golovin <[email protected]> Tue, 08 Feb 2022 07:16:44 +0400
Newsgroups gmane.comp.lib.gnustep.devel
Message-ID <8ae3e739f538a456c7300678d57bc101@iamhere>
On 2022-02-08 02:49:26 +0400 Wolfgang Lux <[email protected]> 
wrote:

>> The attached patch changes the -[dealloc] to do the code chunk 
>> equivalent 
>> to -[setMenu:nil]
>> avoiding that -[NSPopUpButtonCell synchronizeTitleAndSelectedItem]
>> and following.
> 
> 
> didn't have time to look at your second message earlier.
> I like the idea of avoiding the call to setMenu: altogether. That 
> said,
> there is a little problem with your patch: It lets the menu leak. 
> There
> should be a DESTROY(_menu) or RELEASE(_menu) statement after removing
> the observer.

_menu is owned by a superclass and released there. See -[NSCell 
dealloc].

> And I would remove the setMenuView: call. 

Agree.

-- 
SG

<gtam_segfault_on_quit_bug.patch>
gtam_segfault_on_quit_bug.patch (text/x-patch, 757 B)
diff --git a/Source/NSPopUpButtonCell.m b/Source/NSPopUpButtonCell.m
index a60a0ca4d..e38bb42f5 100644
--- a/Source/NSPopUpButtonCell.m
+++ b/Source/NSPopUpButtonCell.m
@@ -138,6 +138,7 @@ static NSImage *_pbc_image[5];
 
 - (void) dealloc
 {
+  NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
   /* 
    * The popup must be closed here, just in case the cell goes away 
    * while the popup is still displayed. In that case the notification
@@ -150,7 +151,10 @@ static NSImage *_pbc_image[5];
 
   if (_menu != nil)
     {
-      [self setMenu: nil];
+      [_menu _setOwnedByPopUp: nil];
+      [nc removeObserver: self
+                    name: nil
+                  object: _menu];
     }
   _selectedItem = nil;
   [super dealloc];