Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do Cocoa apps use so much memory?

Even the standard blank-window Cocoa app that gets built when you make a new Cocoa project in Xcode uses almost 6 MB of memory. What's the reason for this? Is it possible to make an app use less, or does OS X simply manage memory differently for Cocoa apps?

Not that I'm complaining. I know that performance "hardly matters anymore" (edit: what I mean is, it matters less than readability/maintainability/the programmer's time). I'm just curious.

like image 404
Michael Avatar asked Mar 28 '09 21:03

Michael


2 Answers

OS X does a lot of magic with shared memory and copy-on-write pages, so chances are that it doesn't take that much physical RAM for every application.

You can check exactly how memory blocks are mapped by running:

sudo vmmap <PID of the process>
like image 118
Kornel Avatar answered Oct 21 '22 00:10

Kornel


Depends on the all the framework (APIs) you use. Combine that with the VM allocations done by low level ops.

It's only worth trying to reduce the heap alloc (total), as well as the resident size of the code. Making sure your data structs are allocated efficiently and trying to compile with the ever-so-famous "-Os" optimization flag (size optimization). There isn't much you can do about the VM eaten by Cocoa. I wouldn't really worry about it.

like image 39
Rev316 Avatar answered Oct 21 '22 00:10

Rev316