• 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: "Glenn L. Austin" <email@hidden>
  • Date: Thu, 10 Nov 2011 10:10:35 -0800

On Nov 10, 2011, at 9:52 AM, Kyle Sluder wrote:

> On Nov 10, 2011, at 9:33 AM, James Montgomerie <email@hidden> wrote:
>
>> On 9 Nov 2011, at 17:33, Dave Camp wrote:
>>> This was discussed at a WWDC session a couple of years ago. If your app attempts to allocate a large block of memory, and the OS cannot get other processes to give up memory in a timely fashion, your app will be killed.
>>>
>>> It's the reverse of you getting the low memory messages. As you take up more and more memory, the OS has to send the low memory messages to other apps to get them to release memory for you. If you allocate memory faster than the OS can re-claim it from other processes, your app will be terminated.
>>
>> Maybe you didn't mean it this way, but this makes sound as if the foreground app never gets memory warnings, it's just terminated if it uses too much RAM.  This is not true.  In general, the opposite is true - other apps that have been suspended are not 'woken up'  just to be given warnings - they're just terminated.
>
> Read carefully: “If you allocate memory faster than the OS can re-claim it from other processes…” In other words, the system protects against apps that might've gotten trapped in an infinite loop of allocating memory. Better to kill the errant app without sacrificing other apps to its unsatisfiable demands.

Just remember that the memory usage of your application includes your autoreleased objects that haven't yet been released.

As an example, Day-n-Night (one of my products) pulls in sections of two multi-megabyte images (the highest resolution images are 122MB+ decompressed) to create the final image seen on the screen. I added my own autorelease pools in my image management code so that I'm not trying to keep both source images in memory at the same time as the resulting image.

If you're consuming a lot of memory that is later autoreleased, remember that those objects are still allocated until the current autorelease pool is released.  If you never create and release your own autorelease pools, then the only one available is the one created by the event loop and that will only be released when you return to the event loop.

I know that I'm paying a performance penalty for all of those additional autorelease pools, but at the same time my apps continue to run even though I'm working with extremely large images and consuming multiple megabytes of memory.

--
Glenn L. Austin, Computer Wizard and Race Car Driver         <><
"Where there's breath, there's hope!"
<http://www.austin-soft.com>

_______________________________________________

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

References: 
 >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: Jens Alfke <email@hidden>)
 >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: Greg Parker <email@hidden>)
 >Re: Allocating too much memory kills my App rather than returning NULL (From: Wade Tregaskis <email@hidden>)
 >Re: Allocating too much memory kills my App rather than returning NULL (From: Joar Wingfors <email@hidden>)
 >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: Conrad Shultz <email@hidden>)
 >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: Dave Camp <email@hidden>)
 >Re: Allocating too much memory kills my App rather than returning NULL (From: James Montgomerie <email@hidden>)
 >Re: Allocating too much memory kills my App rather than returning NULL (From: Kyle Sluder <email@hidden>)

  • Prev by Date: Re: Allocating too much memory kills my App rather than returning NULL
  • Next by Date: Re: Allocating too much memory kills my App rather than returning NULL
  • 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