Text

Investigating Memory Management in OS X

As I’ve mentioned a few times, I’ve been trying to debug memory usage in an application running under OSX.  I’m pretty sure I’ve conquered all the memory leaks, but I’m still not 100% on what some of the definitions are, but here are some things I have learned:

1) Running inside the debugger from xcode (a.k.a. just go hit the big shiny ‘Run’ button or cmd+r takes about 50% more memory (or more) than without.

2) Running inside the profiler takes 3-4x as much memory as running normally.  This does not include all the truckload of memory that Instruments will allocate while storing every piece of transient memory that your application starts using.  (In my case, though my runtime memory is small, the amount that is transient while doing a lot of network i/o is large, and instruments gets very big, very quickly)

3) I still don’t really understand what Virtual Private Memory is.  I’m pretty sure I have solved all of my memory leak problems, but I can’t find anything that really explains that breakdown (from Activity Monitor) very well.

Some numbers (not including when run under instruments):

Time : Real Mem / Private Mem / Virtual Private Mem

In Debugger:
6:00 : 36.0 MB  / 5.8 MB
6:10 : 35.0 MB  / 7.4 MB
6:20 : 32.9 MB  / 8.2 MB      / 58.2 MB
6:30 : 36.4 MB  / 7.7 MB      / 61.4 MB <— shut down another application, memory increased
6:40 : 36.6 MB  / 10.0 MB     / 61.4 MB
6:50 : 37.3 MB  / 10.8 MB     / 62.4 MB
7:00 : 38.1 MB  / 9.3 MB      / 62.4 MB

Outside Debugger:

9:30 : 21.8 MB  / 6.8 MB      / 59.8 MB
10:00: 28.2 MB  / 11.8 MB     / 55.4 MB
10:30: 31.4 MB  / 12.5 MB     / 56.9 MB

After Bug Fix:

11:00: 21.1 MB  / 6.0 MB      / 60.3 MB
11:15: 23.3 MB  / 7.9 MB      / 61.1 MB
11:30  21.2 MB  / 8.0 MB      / 53.9 MB
 2:00: 30.0 MB  / 11.5 MB     / 60.1 MB
 2:30: 30.9 MB  / 10.3 MB     / 60.1 MB
 3:00: 31.3 MB  / 10.9 MB     / 61.1 MB
 3:30: 31.3 MB  / 10.9 MB     / 61.1 MB
 4:00: 31.3 MB  / 10.9 MB     / 61.1 MB
 4:30: 31.3 MB  / 10.9 MB     / 61.1 MB

I am pretty sure all the leaks are gone, but it seems like it doesn’t like to free memory once it is allocated very often, too.  Maybe someone who has more knowledge can comment?

Photo
I have got to say, I am consistently impressed with how useful the Apple XCode tool Instruments is.  It is stuffed full of useful utilities and diagnostic tools, and it is quite the tool in the toolchest.  I had absolutely no idea how bad at memory management my application within its threads (it was leaking thread handles, even!) but now I&#8217;ve not only cleaned up a lot of those, but I&#8217;ve refactored a good chunk of the code that I personally found to be &#8216;ugly&#8217; into much more easily maintainable blocks.

I have got to say, I am consistently impressed with how useful the Apple XCode tool Instruments is.  It is stuffed full of useful utilities and diagnostic tools, and it is quite the tool in the toolchest.  I had absolutely no idea how bad at memory management my application within its threads (it was leaking thread handles, even!) but now I’ve not only cleaned up a lot of those, but I’ve refactored a good chunk of the code that I personally found to be ‘ugly’ into much more easily maintainable blocks.

Link

bdarfler:

Interesting AWS choice backing AMIs instead of a more complicated chef/puppet setup.

worth a read

Tags: devops aws heroku
Photoset

railing nearly done, everything but bottom steps are complete, have to lay a little more concrete for support for the big stairs at the base (connecting to driveway).  Exciting!  <1 day of work remains.

Photo
the profiling tool with XCode is pretty handy.  Apparently ARC is not nearly as good at magical memory management as I was hoping, and now it&#8217;s time to figure out why it&#8217;s not doing what I wanted&#8230;

the profiling tool with XCode is pretty handy.  Apparently ARC is not nearly as good at magical memory management as I was hoping, and now it’s time to figure out why it’s not doing what I wanted…

Photo
Added a slider so that you can keep queries around indefinitely (or variable length of time).  The timer is not actually right on&#8230;  10 seconds is about 13 seconds really.  Code needs some cleaning up but it&#8217;s nearly complete now.

Added a slider so that you can keep queries around indefinitely (or variable length of time).  The timer is not actually right on…  10 seconds is about 13 seconds really.  Code needs some cleaning up but it’s nearly complete now.

Photo
Still have to clean up a few things that aren&#8217;t 100% threadsafe, but other than that only a few minor features left to go.

Still have to clean up a few things that aren’t 100% threadsafe, but other than that only a few minor features left to go.

Text

NSTextView not thread safe

I had been tracking down all sorts of fun stuff only to discover that NSTextView is not thread safe.  I mean, I guess I shouldn’t be surprised.  Going to have to go through and make sure all of my UI elements are updated in the main thread instead of in any sub-threads right now.  In fact, I kind of want to push a lot of data updates back into the main thread.  I bet this solves all sorts of stupid problem I was having.

*sigh*

At least this explains a great many things.

Photoset

Been working on improving they layouts of the db monitor app, improving usability and versatility.  Getting closer!

Photoset

Decks are done except for two staircases down below (small ones), closing up the area underneath the deck below, and finish work (railings, their tops, etc)  Looking great.