bug-gnustep
[Top][All Lists]
Advanced

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

Re: [PATCH] Fix NSMenu retainCount problem


From: Fred Kiefer
Subject: Re: [PATCH] Fix NSMenu retainCount problem
Date: Fri, 06 Feb 2004 01:25:47 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030821

Quentin Mathé wrote:
Le 5 févr. 04, à 22:37, Fred Kiefer a écrit :

Quentin Mathé wrote:

I did spend some time on this problem and I would like to only accept half of your patches. First I have to admit, that I was wrong with the notification center. There everythign seems to be ok. On the other hand I was right that the problem should also occure if you only create a menu and released it again. And this gets solved by your patch on NSMenuView, which really doesnt do any harm as the GSTitleView never uses the menu, it only refers to its owner ivar.


ok.

In the second case you may have been mislead by the notification still hanging around. When trying to investigate memory leaks one cannot be to carefull to wrap extra layers of auto release pools around the operations in question. Only when the count is still wrong on the highest level, than there is an actual problem.


I think it's the case (the count is wrong at the highest level, here NSMenu) or I'm not understanding what you have said.

Ok, so I did not make myself clear. Look at the example below.

Here is an example :
with Cocoa, the code below release and dealloc the menu variable.

NSMenu *menu = [[NSMenu alloc] initWithTitle:@"Youlà"];

[menu addItem:[[NSMenuItem alloc] initWithTitle:@"You" action:@selector(john:) keyEquivalent:@""]];
[menu release];

with GNUstep, the same code doesn't dealloc the menu because in NSMenu _notifications retain the menu itself (in my experience). That's not nice, because you must remove each menu item retained in the menu to be able to dealloc it.


  menu = [[NSMenu alloc] initWithTitle: @"boum"];

  NSLog(@"menu retain count before = %d", [menu retainCount]);
  {
      CREATE_AUTORELEASE_POOL(pool2);
      menuItem = [[NSMenuItem alloc] init];
      [menu addItem: menuItem];
      RELEASE(menuItem);
      RELEASE(pool2);
  }
  NSLog(@"menu retain count after = %d", [menu retainCount]);

For me this results in a menu with a retain count of one, so it will be deallocated after the next release. GNUSteop might need and internal autorelease pool in one of the NSMenu methods

Other example :
NSMenu *menu = [[NSMenu alloc] initWithTitle:@"Youlà"];
NSMenu *item = [[NSMenuItem alloc] initWithTitle:@"You" action:@selector(john:) keyEquivalent:@""];

[menu addItem:item];
[menu release];
menu = [[NSMenu alloc] initWithTitle:@"other"];
[menu addItem:item];

The code above which is ok with Cocoa doesn't work with GNUstep.


Yes, this just shows that your cleanup code in NSMenu does the right thing. That is why I wanted to use it. This has nothing to do with the notifications.

Last words. You decide... You are involved for far more time than me in GNUstep :-).

This would be a very bad argument, if this would be the only one. I hope I have a few more ;-)





reply via email to

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