On Apr 20, 2010, at 10:36 AM, Bill wrote:

>> And what make NSCache and NSDiscardableContent not appropriate here ? 
> 
> They are not inappropriate, but they require a lot more work than a simple 
> warning sent via a notification or other means.

The iPhone has a much simpler memory model than Mac OS (or Windows or Linux). 
It doesn’t have virtual memory, and it also has very limited RAM. This makes 
low-memory warnings necessary.

With virtual memory, things are more complicated. The good news is that on Mac 
OS your process won’t “run out of memory” until it allocates about 3GB of heap 
if it’s 32 bit; if it’s 64-bit it will never run out of memory*. The bad news 
is that before that happens, the VM paging is likely to slow your machine to a 
crawl, as everything else on the system gets paged out.

So the danger on Mac OS X is not running out of memory, it’s using too much RAM 
and swap space, causing performance to suffer. Avoiding this is tricky because 
it depends on the differences between address space, RAM and backing store. You 
can allocate a gigabyte of address space with no ill effects as long as you 
don’t map any of it in. But conversely, merely accessing a large 
already-malloced block might cause your process to block for hundreds of 
milliseconds if that address space was paged out.

NSCache and NSDiscardableContent are high-level constructs that try to simplify 
these decisions and make them easier to use. Yes, they’re more complex than a 
simple “please free up memory right now” warning. But they make a lot more 
sense on Mac OS. (And in practice, they end up automating what you’d probably 
already be doing in response to a low-memory warning, i.e. looking for data 
that can be safely thrown away and freeing it.)

—Jens

* It will, however, eventually fill up your hard disk with VM backing store 
files. When this happens the OS starts suspending processes while it puts up a 
critical alert asking you to quit apps or free up disk 
space._______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to