suppose If there is a case where it fails due to insufficient memory.
To address that point specifically:
(On iOS), When memory is low, apps get memory warnings and should free resources. If that’s not enough, suspended apps will be terminated.
The only situation where you will really run out of memory is if you ask for a ridiculously large allocation, and that indicates a bug in your program.
(The same is also true on other platforms, except embedded systems without virtual memory. Unless you run out of virtual address space, memory allocations will always succeed even when physical RAM is exhausted; the problem is dealt with by other mechanisms, such as Linux’s “OOM Killer”. Personally, in my C++ code I assume that memory allocation cannot fail.)
More generally: if the API has some way of reporting an error, try to handle it; if it doesn’t, assume that it cannot fail for valid parameters.
Topic:
UI Frameworks
SubTopic:
UIKit
Tags: