• 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: Can't get setDelegate to work on NSMenu attached to NSStatusItem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can't get setDelegate to work on NSMenu attached to NSStatusItem


  • Subject: Re: Can't get setDelegate to work on NSMenu attached to NSStatusItem
  • From: Quincey Morris <email@hidden>
  • Date: Tue, 3 Mar 2009 13:30:06 -0800

On Mar 3, 2009, at 12:50, Nick Zitzmann wrote:

On Mar 3, 2009, at 1:33 PM, Quincey Morris wrote:

I don't know of any documented API contract that says [NSMenu initWithTitle:] never fails, so checking the returned value seems prudent.

In the case of Apple's documentation, it's the other way around. Unless the documentation mentions that it may return nil, it's guaranteed to return something.

Yet even *that* would need to be documented. Otherwise, as an API contract, it isn't worth the paper it isn't printed on.


In addition, I've always assumed that 'alloc' could potentially return nil. In that case, the result of the initialization would be nil too, and so needs to be checked. (Is that wrong? Is an exception thrown if there is no memory available? If so, is that documented somewhere?)

It doesn't seem to be documented, but I think it will return nil only if (1) there was not enough contiguous RAM in the program's VM space to allocate the object, or (2) there was, but the user has run out of disk space for swap files. But if this happens, the program is pretty much screwed anyway, because it's going to crash.

Yes, I'm aware of the "is pretty much screwed" scenario, but I think there are in fact some recoverable scenarios. One involves a sequence of very large (valid) allocations gobbling up VM space so that it becomes impossible to create a humbler NS... object of some kind. If the application doesn't crash right away, returning nil (or NO) back through the sequence could release all the memory and allow the application to continue with an error message.


Another scenario is a memory-limited environment like the iPhone.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Can't get setDelegate to work on NSMenu attached to NSStatusItem
      • From: Michael Ash <email@hidden>
References: 
 >Can't get setDelegate to work on NSMenu attached to NSStatusItem (From: "Mark D. Gerl" <email@hidden>)
 >Re: Can't get setDelegate to work on NSMenu attached to NSStatusItem (From: Nick Zitzmann <email@hidden>)
 >Re: Can't get setDelegate to work on NSMenu attached to NSStatusItem (From: "Mark D. Gerl" <email@hidden>)
 >Re: Can't get setDelegate to work on NSMenu attached to NSStatusItem (From: Nick Zitzmann <email@hidden>)
 >Re: Can't get setDelegate to work on NSMenu attached to NSStatusItem (From: Quincey Morris <email@hidden>)
 >Re: Can't get setDelegate to work on NSMenu attached to NSStatusItem (From: Nick Zitzmann <email@hidden>)

  • Prev by Date: Re: integrate google map in cocoa app?
  • Next by Date: Re: Changing NSTableView cell immediately before editing
  • Previous by thread: Re: Can't get setDelegate to work on NSMenu attached to NSStatusItem
  • Next by thread: Re: Can't get setDelegate to work on NSMenu attached to NSStatusItem
  • Index(es):
    • Date
    • Thread