Re: setMenu: nil does not release a menu ?
Re: setMenu: nil does not release a menu ?
- Subject: Re: setMenu: nil does not release a menu ?
- From: Shawn Erickson <email@hidden>
- Date: Thu, 22 May 2003 08:10:54 -0700
On Thursday, May 22, 2003, at 07:34 AM, Tobias Hermann wrote:
>
hi!
>
>
I am experimenting with NSMenus.
>
>
I experienced a very strange behavior:
>
Consider aMenu as a ready configured NSMenu, aView as some NSView
>
subclass.
>
>
[aView setMenu: aMenu]; does retain the menu, that is what I would
>
expect, and it is ok.
>
>
But:
>
>
[aView setMenu: nil]; does NOT release aMenu again.
>
>
Is this normal ? I get unwanted memory leaks that way! I want to
>
release my menu properly when I don't need it anymore!
Not having enough time to get Omni's great memory tool going (need a
license...) and I am not good with Apple's tool at the moment. so...
If I run the following...
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSPopUpButton* popup = [[NSPopUpButton alloc]
initWithFrame:NSMakeRect(0,0,25,25)
pullsDown:NO];
NSMenu* menu = [[NSMenu alloc] initWithTitle:@"Test"];
NSLog(@"retain count:%d", [menu retainCount]);
[popup setMenu:menu];
NSLog(@"retain count:%d", [menu retainCount]);
[popup setMenu:menu];
NSLog(@"retain count:%d", [menu retainCount]);
[popup setMenu:menu];
NSLog(@"retain count:%d", [menu retainCount]);
[popup setMenu:nil];
NSLog(@"retain count:%d", [menu retainCount]);
[pool release];
return 0;
}
I get the following good result...
2003-05-22 07:54:37.401 test[868] retain count:1
2003-05-22 07:54:37.402 test[868] retain count:2
2003-05-22 07:54:37.402 test[868] retain count:2
2003-05-22 07:54:37.402 test[868] retain count:2
2003-05-22 07:54:37.402 test[868] retain count:1
If I run the following, with popup coming from a nib placed in a
visible window...
- (void)awakeFromNib
{
NSMenu* menu = [[NSMenu alloc] initWithTitle:@"Test"];
NSLog(@"retain count:%d", [menu retainCount]);
[popup setMenu:menu];
NSLog(@"retain count:%d", [menu retainCount]);
[popup setMenu:menu];
NSLog(@"retain count:%d", [menu retainCount]);
[popup setMenu:menu];
NSLog(@"retain count:%d", [menu retainCount]);
[popup setMenu:nil];
NSLog(@"retain count:%d", [menu retainCount]);
}
I get the following bad result...
2003-05-22 07:54:37.401 test[868] retain count:1
2003-05-22 07:54:37.402 test[868] retain count:2
2003-05-22 07:54:37.402 test[868] retain count:3
2003-05-22 07:54:37.402 test[868] retain count:4
2003-05-22 07:54:37.402 test[868] retain count:4
Humm... (sorry have to go to work)
-Shawn
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.