There’s no point in trying to recover from a
malloc
failure on OS X, because by the time you detect the failure and try to recover, your process is likely to already be doomed. There’s no need to do your own logging, becausemalloc
itself does a good job of that. And finally there’s no real need to even explicitly abort, because anymalloc
failure is virtually guaranteed to result in an instantaneous crash with a good stack trace.
This is excellent advice. Peppering your code with if
statements harms readability and simplicity.
It’s still a good idea to check large (many MB) malloc
s, but I can’t imagine recovering gracefully from a situation where 32 byte memory allocations are failing on a modern desktop.