Best way to handle malloc crash in Cocoa

Although this does not happen often, there are several cases where my Cocoa application allocates very large amounts of memory, which allows me to worry about malloc crashing. What is the best way to handle this kind of crashes in a Cocoa application? I have heard that Exceptions are generally discouraged in this development environment, but is this the case when they would be useful?

+3
source share
3 answers

If you have access denied because you ran out of memory, most likely there was some distribution error in some environment that left the application in an undefined state.

, -, , .

"" , "" , .

. , , , ( , , - ).

, log exit.

, , . , , , , , , .

, .

( , ).

+5

, , .

, Cocoa, , , ++ # /.

, , ? ? / ? ? ?

malloc , , , , ? , .

+1

, , . , .

The standard in C applications is to write a function void xmalloc(size_t size);that will check the return value of malloc, and if NULL, print an error for stderr, and then call the abort () function. That way you just use xmallocin all your code and donโ€™t think about it. If you run out of memory, luck and your application will die.

0
source

Source: https://habr.com/ru/post/1726696/


All Articles