Re: NSTextField and contextual menu (solved)
Re: NSTextField and contextual menu (solved)
- Subject: Re: NSTextField and contextual menu (solved)
- From: Ondra Cada <email@hidden>
- Date: Sun, 15 Sep 2002 18:41:32 +0200
On Sunday, September 15, 2002, at 06:26 , Arthur Clemens wrote:
menu = [[NSMenu alloc] initWithTitle:@"Menu"];
for (i=0; i<[charArray count]; ++i) {
item = [[NSMenuItem alloc] init];
...
[item release];
}
...
[menu release];
Not that it is too important, but I keep seeing this pattern of
foo=[[Foo alloc] init];
...
[fo release];
so often, but -- as I am slowly becoming tired to repeat -- it is somewhat
wrong, since it brings a risk of a leak. The pattern is all right only if
you are completely sure the code would never ever raise (which is pretty
rare).
In majority of cases the proper patter is
foo=[[[Foo alloc] init] autorelease];
...
Beside being more safe, its other advantage is better robustness: since
creation and releasing is at the very same place, the danger of forgetting
a release or (much worse) doing one too many is much less than in the
pattern of yours.
In the minority of cases when you for some reason can't afford
autoreleasing you should enclose the guts in NS_DURING/NS_HANDLER.
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc
_______________________________________________
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.