• 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: Checking for nil-return
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Checking for nil-return


  • Subject: Re: Checking for nil-return
  • From: Greg Parker <email@hidden>
  • Date: Tue, 5 Oct 2010 09:25:28 -0700

On Oct 5, 2010, at 7:07 AM, Remco Poelstra wrote:
> I'm cleaning up my code and I'm wondering about constructs like the next one:
> [NSNumber numberWithUnsignedChar:i]
> The documentation does not say it can return nil on failure, but does that mean it simply will never fail? What if there is no memory left?

If you truly run out of memory, you should expect to crash.

A 32-bit process can run out of virtual address space. When that happens, allocations return NULL. But so much other code is allocate-or-die that the process is unlikely to survive long enough to do anything about the problem. (For example, objc_msgSend() sometimes needs to allocate memory, and it has no fallback if allocation fails.)

A process can also use all available RAM. You won't get NULL from allocations, but your process is still unlikely to survive. On Mac OS, your machine will start paging, and most likely the user will get frustrated enough to restart the machine first. On iOS, the system sends memory warnings and then starts killing processes to make room.


--
Greg Parker     email@hidden     Runtime Wrangler


_______________________________________________

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

References: 
 >Checking for nil-return (From: Remco Poelstra <email@hidden>)

  • Prev by Date: Re: Checking for nil-return
  • Next by Date: Re: JDBC from Cocoa or the like
  • Previous by thread: Re: Checking for nil-return
  • Next by thread: JDBC from Cocoa or the like
  • Index(es):
    • Date
    • Thread