Re: Xcode 4.3.1 memory usage
Re: Xcode 4.3.1 memory usage
- Subject: Re: Xcode 4.3.1 memory usage
- From: Seth Willits <email@hidden>
- Date: Mon, 12 Mar 2012 23:23:11 -0700
On Mar 12, 2012, at 9:50 PM, Brad Oliver wrote:
> 1. What is causing Xcode to need *so much memory* as my day goes on? Is this a bad memory leak or by design?
I'm sure it's neither.
All applications have this problem of ever-increasing memory usage. What makes it noticeable is when the application can use lots of memory at once. For example, Safari has this same problem, and a couple of my applications do too.
I'm not a Mach internals expert so I'm not 110% sure of the details, but it was only after screaming at Activity Monitor / Instruments / heap / vmmap for days, multiple times, over a few years, did I put these pieces together. Assume there's a possibility that this is just dead wrong, but I'm pretty sure it's not… This is my understanding:
When an application allocates gajillions of little objects, memory usage increases and little objects are scattered all over the heap making it impossible for the system to pull back all of that memory.
It's better to think of it as memory *allocation* rather than memory *usage*. Xcode has 7 GB allocated to it, but it's almost certainly actually only using a small percentage of that. I have one application in particular which uses less than five megabytes of memory, but because certain processes caused system frameworks to temporarily use a bunch more, the overall persistent allocation is over a hundred megabytes. Some users attribute this to poor coding and leaks when it's neither. It just happens that although most of that memory was used for transient objects, there's at least one persistent one in each page which prevents the OS from taking the page back.
My understanding is that "the solution" to this problem was introduced a loooong time ago: NSZone. You create a zone, allocate all of your gajillion transient objects in it, and when you know you're done with all of them, you can free the zone and that entire chunk of memory gets nuked and the OS takes it back. Apple decided to abandon zones several OS versions ago, and I don't think there's any other solution to this problem available, so I don't think there's anything that can be done about it except using multiple temporary processes.
I would love to actually read a good explanation of this from an engineer who knows the nitty gritty details, but one doesn't exist. (An explanation — though I wonder if such an engineer exists as well. ;-)
--
Seth Willits
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden