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);
}