Macintosh memory management

mac-memory

This is a nerd post. Sorry, non-nerds…

I have been using Macintoshes since the 1980s. The Macintosh operating system has gone through many changes in that time, and it’s one of the best computer operating systems in existence. Though my favorite all-time operating system was Solaris, the version of Unix produced by Sun Microsystems. A few months ago, Apple released version 10.9 of the Mac OS X operating system, also known as Mavericks. I like Mavericks (not least because it was free).

If you turn your computer on and off every day, memory management is of little concern to you. However, if you leave your computer running all the time, as I do, and especially if you have an older computer without the abundance of memory in newer computers, then memory management matters.

One of the wonderful things about the Macintosh OS X operating system is that it is extremely stable. A Mac can be left running for months without needing a reboot. I’ve seen Solaris computers run for more than a year without needing a reboot. But stability is one thing, and memory management is another.

The issue is probably a new concept for non-nerds: memory leaks. Applications frequently contain memory leaks. Memory leaks are generally caused by lazy programming. Programs request memory from the operating system for temporary use, and with many programming languages it is the responsibility of the programmer to release this memory when it is no longer needed. That often fails to happen. Memory leaks pile on top of memory leaks, and soon your computer starts to get low on RAM. When this happens on a Macintosh, you may see the spinning beach ball icon while the operating system comes up with the requested memory. When the computer’s physical memory (or RAM) is exhausted, the computer will resort to “swap” memory — using disk space (which is much slower than RAM) to temporarily store the contents of RAM to disk, then paging the contents back and forth from disk to RAM as needed by the running program. This ability to swap is a sophisticated function of good operating systems that has been around since at least the 1990s. It’s better than simply running out of RAM (which is what used to happen). But swapping is slow. You may have to wait, which is what the spinning beach ball is all about.

Apple’s OS X Mavericks made some significant changes in memory management. The concept is that unused RAM is wasted. So OS X uses almost all of the computer’s RAM all of the time. This can be misleading, because the computer may appear to be more memory-starved than it really is.

But here’s the problem. Applications leak memory, and that’s not the operating system’s fault. When an application leaks memory, the memory can be recovered only by stopping and restarting the application. Here’s a for-example.

For security reasons, to prevent tracking by snoopers like Facebook and Google, I always have two browsers running. In one browser (Safari), I run Facebook and Google applications such as Google analytics. In Safari, that’s ALL I do. It doesn’t matter if Facebook and Google track me, because I don’t go anywhere else in that browser. I do all my real browsing in Chrome, using multiple tabs in an Incognito window, which does not save cookies.

As Chrome and Safari continue to run, often for days, they leak memory. This may or may not be a problem caused by the browser itself. Most web pages these days use some sort of god-awful programming language such as Javascript, so the filthy rotten programming on the web pages hogs memory, then leaks it. So, if you leave a browser running for a long time, your computer’s memory gets leaked, or wasted, and the computer’s operating system must jump through hoops and bend over backwards to keep shoveling RAM to the browser. Facebook’s programming is a horrible memory leaker. I often leave Facebook running, but I close the Facebook page and reopen it occasionally to release the memory it’s wasting. (The people at Facebook are lousy programmers.)

So what’s the bottom line for Mac users, especially for you non-nerds? First, upgrade to Mavericks if you haven’t already. Second, if you see a spinning beach ball, consider quitting from open applications and restarting the applications you need. It’s not really necessary to reboot the computer.

For nerds, you can monitor your computer’s memory usage with Activity Monitor. It is possible to “clean” a Mac’s memory and force all the garbage out of RAM. You probably don’t want to, though, because in doing so you’ll also defeat some of the clever methods Mac OS X uses to optimize the use of available physical RAM. But if you know what you’re doing, a little app named Memory Clean will do this for you, while also continuously displaying in the menu bar the amount of free RAM available. You also can clear the Mac’s memory in a terminal window by typing “sudo purge.” The purge command, which comes with the Mac, will do the same thing. In Activity Monitor, watch the “memory pressure” window. If it’s anything but all green, consider taking action to get it back in the green by closing applications and reopening them as needed.

My iMac is now six years old. One of these years I’ll replace it. But for now I have to live with 4 gigabytes of RAM, which is the maximum my older iMac can take.

And if you see a spinning beach ball, it’s not your Mac’s fault. It’s just that your Mac is trying heroically to deal with the crimes of lousy programmers.

One thought on “Macintosh memory management”

Leave a Reply

Your email address will not be published. Required fields are marked *