Hacker News new | past | comments | ask | show | jobs | submit login

Apps don't get killed for requesting memory. They get killed when they're running in the background and other apps request memory.

Can't malloc return NULL and the app act accordingly ("your picture is too big, so i am not going to edit it").

Thats exactly what happens. You're free to run:

  void *foo = malloc(INT_MAX);
foo will be NULL. The rest of the app will continue to run without any problems.

// edit: Here's what happens when you do run that (the last line is a NSLog() to show the address of foo):

  Malloc(4972,0x3e088868) malloc: *** mmap(size=2147483648) failed (error code=12)
  *** error: can't allocate region
  *** set a breakpoint in malloc_error_break to debug
  2010-09-12 19:44:59.154 Malloc[4972:307] malloc: 0x0
// edit 2: Here's the code: http://thisismyinter.net/misc/hn/Malloc.zip



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: