• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Allocating too much memory kills my App rather than returning NULL
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Allocating too much memory kills my App rather than returning NULL


  • Subject: Re: Allocating too much memory kills my App rather than returning NULL
  • From: Greg Parker <email@hidden>
  • Date: Mon, 7 Nov 2011 07:59:43 -0800

On Nov 4, 2011, at 6:40 PM, Don Quixote de la Mancha wrote:
> My code checks that calloc() returns valid pointers for each
> allocation attempted when creating a new grid.  If all the allocations
> succeed, I copy the data in the old grid into the center of the new
> one, then free() each array in the old grid.
>
> If calloc() ever returns NULL while attempting to allocate the new
> grid, I back out all of the successful allocations by passing each
> array pointer to free().  Then I display an alert to the user to
> advise them that there is not enough memory for their desired grid
> size, and suggest trying a smaller one.

This is not a safe pattern in a multi-threaded application. You may be checking for failed allocations and responding correctly, but to a close approximation no code anywhere else does so. For example, objc_msgSend sometimes needs to allocate memory, and has no way to recover if it cannot. If some other thread were working at the same time you caused allocation failures, then that thread is likely to crash.


--
Greg Parker     email@hidden     Runtime Wrangler


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Allocating too much memory kills my App rather than returning NULL
      • From: Don Quixote de la Mancha <email@hidden>
    • Re: Allocating too much memory kills my App rather than returning NULL
      • From: Wade Tregaskis <email@hidden>
References: 
 >Allocating too much memory kills my App rather than returning NULL (From: Don Quixote de la Mancha <email@hidden>)

  • Prev by Date: Re: How to highlight the current line in NSTextView?
  • Next by Date: ObjectController preventing window from closing
  • Previous by thread: Re: Allocating too much memory kills my App rather than returning NULL
  • Next by thread: Re: Allocating too much memory kills my App rather than returning NULL
  • Index(es):
    • Date
    • Thread