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 protected] Runtime Wrangler _______________________________________________ Cocoa-dev mailing list ([email protected]) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
