• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTextField and contextual menu (solved)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.
References: 
 >Re: NSTextField and contextual menu (solved) (From: Arthur Clemens <email@hidden>)

  • Prev by Date: Property List Services and XML
  • Next by Date: Help with Help
  • Previous by thread: Re: NSTextField and contextual menu (solved)
  • Next by thread: NSFilesPromisePboardType
  • Index(es):
    • Date
    • Thread