NSMenu leak when connected to outlet with interface builder?
NSMenu leak when connected to outlet with interface builder?
- Subject: NSMenu leak when connected to outlet with interface builder?
- From: Jesse Grosjean <email@hidden>
- Date: Fri, 30 Jan 2004 16:58:20 -0500
It seems that when you connect a new NSMenu (popup menu) to an outlet
in interface builder that menu will then be leaked. Using the default
document based project I have what I think is a very basic setup. I
give MyDocument a popupMenu outlet and I connect the default popup menu
with (two items named item1 and item2) to this outlet using interface
builder.
// MyDocument has an NSMenu outlet that's connect to a popup menu in
interface builder.
@interface MyDocument : NSDocument {
IBOutlet NSMenu *popupMenu;
}
@end
With this setup every-time I create and then close a document I leak a
NSMenu and two NSMenuItems. My guess is that this is not the intended
behavior, please let me know if I'm missing some concept and this IS
intended.
The only way that I can seem to fix the problem is if I send the popup
menu releases for it's entire retain count minus 2... like this:
@implementation MyDocument
- (id)init {
if (self = [super init]) {
}
return self;
}
- (void)dealloc {
int count = [popupMenu retainCount] - 2;
while (count--)
[popupMenu release];
[super dealloc];
}
- (NSString *)windowNibName {
return @"MyDocument";
}
@end
Can anyone tell me what's going on here, and what the best way to solve
the problem is? Sending those extra releases looks a little dangerous
to me especially if this gets fixed in the future, but I'm not sure how
else to handle the problem.
Thanks,
Jesse
_______________________________________________
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.