[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] Fix NSMenu retainCount problem
From: |
Quentin Mathé |
Subject: |
Re: [PATCH] Fix NSMenu retainCount problem |
Date: |
Fri, 6 Feb 2004 18:45:35 +0100 |
Le 6 févr. 04, à 02:43, Quentin Mathé a écrit :
Le 6 févr. 04, à 01:25, Fred Kiefer a écrit :
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
For me too. but...
It's more complex than that. The autoreleasepool in the block is just
showing that the notifications involve the problem we are talking
about. The problem will rise again when we will have some
notifications pushed back by using _notifications variable.
Here is an example :
menu = [[NSMenu alloc] initWithTitle: @"boum"];
[menu setMenuChangedMessagesEnabled:NO];
{
CREATE_AUTORELEASE_POOL(pool2);
menuItem = [[NSMenuItem alloc] init];
[menu addItem: menuItem];
RELEASE(menuItem);
RELEASE(pool2);
}
NSLog(@"menu retain count after = %d", [menu retainCount]);
With this example, NSLog will show a retain count which is superior to
1 (because _notifications variable will be used to retain notifications
created to be executed later). We need to fix that and I hope you
understand that your solution with an extra autorelease pool is a hack
which doesn't solve the problem entirely.
In other terms, I just want to have with my GNUstep system the code
below exits on the third NSLog with the output :
2004-02-06 18:37:51.831 MyProgram[433] Menu1 1 :
2004-02-06 18:37:51.879 MyProgram[433] Menu2 1 :
MyProgram has exited due to signal blabla
Here is the code I'm talking about :
int main(int argc, const char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSMenu *menu = [[NSMenu alloc] initWithTitle:@"Youlà"];
[menu setMenuChangedMessagesEnabled:NO];
NSLog(@"Menu1 %d :", [menu retainCount]);
[menu addItem:[[NSMenuItem alloc] initWithTitle:@"You" action:NULL
keyEquivalent:@""]];
NSLog(@"Menu2 %d :", [menu retainCount]);
[menu release];
NSLog(@"Menu3 %d :", [menu retainCount]);
[pool release];
return NSApplicationMain(argc, argv);
}
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.
the call [menu addItem:item] has nothing to the GSTitleView issue, it
has to do with the notifications.
... want to write : has nothing to do with the GSTitleView issue
Quentin.
--
Quentin Mathé
qmathe@club-internet.fr
- [PATCH] Fix NSMenu retainCount problem, Quentin Mathé, 2004/02/05
- Re: [PATCH] Fix NSMenu retainCount problem, Fred Kiefer, 2004/02/05
- Re: [PATCH] Fix NSMenu retainCount problem, Quentin Mathé, 2004/02/05
- Re: [PATCH] Fix NSMenu retainCount problem, Fred Kiefer, 2004/02/05
- Re: [PATCH] Fix NSMenu retainCount problem, Quentin Mathé, 2004/02/05
- Re: [PATCH] Fix NSMenu retainCount problem,
Quentin Mathé <=
- Re: [PATCH] Fix NSMenu retainCount problem, Fred Kiefer, 2004/02/06
- Re: [PATCH] Fix NSMenu retainCount problem, Quentin Mathé, 2004/02/07
- Re: [PATCH] Fix NSMenu retainCount problem, Alexander Malmberg, 2004/02/07
- Re: [PATCH] Fix NSMenu retainCount problem, Richard Frith-Macdonald, 2004/02/07
- Re: [PATCH] Fix NSMenu retainCount problem, Quentin Mathé, 2004/02/07
- Re: [PATCH] Fix NSMenu retainCount problem, Richard Frith-Macdonald, 2004/02/07
- Re: [PATCH] Fix NSMenu retainCount problem, Quentin Mathé, 2004/02/07