Re: NSUserDefaults allocation size and CALayer memory usage

2015-06-29 Thread Jens Alfke

 On Jun 28, 2015, at 11:35 PM, Henrik Granaas-Helmers helm...@me.com wrote:
 
 1. NSUserDefaults seems to allocate 16 MB memory at load. I can't see myself 
 using a megabyte—let alone 16 of those. It would be very interesting to know 
 why it allocates so much, and if there is a way to encourage NSUserDefaults 
 to grab less.

Probably you’re looking at the memory allocated by a lot of system components 
during app initialization, or of components that get initialized lazily during 
the first call to NSUserDefaults.

 2. I create a couple of CoreAnimation layers that I think are large 
 (5120x2880 px). I would expect that to occupy 450 MB (5120*2880*32/1024/1024) 
 of memory. But instead it only takes up one fourth of that. What is this 
 sorcery?

Much of that memory is likely allocated in the WindowServer’s address space, or 
even on the GPU.

General advice: Don’t micromanage your use of memory, and as with all 
optimization, wait until you have something working before trying to 
performance-tune. 

And as Quincey said, in any modern OS it becomes very tricky to say how much 
memory is being used. It’s complicated by factors like virtual memory, paging, 
memory-mapped files, shared memory, copy-on-write, GPU vs CPU …

—Jens
___

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

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

Re: NSUserDefaults allocation size and CALayer memory usage

2015-06-29 Thread David Duncan

 On Jun 28, 2015, at 11:35 PM, Henrik Granaas-Helmers helm...@me.com wrote:
 
 Hi there,
 
 I am new to Apple development, and new to this list. I have two questions 
 about memory on OS X.
 
 1. NSUserDefaults seems to allocate 16 MB memory at load. I can't see myself 
 using a megabyte—let alone 16 of those. It would be very interesting to know 
 why it allocates so much, and if there is a way to encourage NSUserDefaults 
 to grab less.
 
 2. I create a couple of CoreAnimation layers that I think are large 
 (5120x2880 px). I would expect that to occupy 450 MB (5120*2880*32/1024/1024) 
 of memory. But instead it only takes up one fourth of that. What is this 
 sorcery?

You forgot to divide by 8 (you’re counting mega-bits, not mega-bytes).

 
 
 --
 Henrik Granaas-Helmers
 ___
 
 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:
 https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
 
 This email sent to david.dun...@apple.com

--
David Duncan


___

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

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

Re: NSUserDefaults allocation size and CALayer memory usage

2015-06-29 Thread Quincey Morris
On Jun 28, 2015, at 23:35 , Henrik Granaas-Helmers helm...@me.com wrote:
 
 1. NSUserDefaults seems to allocate 16 MB memory at load. I can't see myself 
 using a megabyte—let alone 16 of those. It would be very interesting to know 
 why it allocates so much, and if there is a way to encourage NSUserDefaults 
 to grab less.
 
 2. I create a couple of CoreAnimation layers that I think are large 
 (5120x2880 px). I would expect that to occupy 450 MB (5120*2880*32/1024/1024) 
 of memory. But instead it only takes up one fourth of that. What is this 
 sorcery?

Where are these numbers coming from? Instruments?

It’s very hard to reason about memory at the app level, because memory usage is 
not simple. Memory can be mapped or shared or reclaimable in time of need, or 
address space can be consumed without any actual memory. You don’t know in 
general whether such numbers represent an actual increase in the use of memory 
resources, or whether they’re an accounting fiction.

In regard to the CA layers, keep in mind that OS X can compress memory contents 
on the fly (since, er, Yosemite or Mavericks, I think). Maybe that’s the 
explanation in this case.

The resource usage that we’ve been advised by Apple to watch are the debug 
“gauges” that appear when you’re debugging in Xcode. Does the memory usage 
gauge give you any reason to think your app is using too much memory?



___

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

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