No Gravatar

For people (like me) who came to the Mac from Windows, there's one big difference with many (but not all) programs when you close them. In Windows, closing the program's window usually (99.9% of the time) ends the program. It's removed from system memory (RAM), freeing up that space. On the Mac, however, that's not necessarily true. Sometimes you're just sending the window away, but the program is still running in the background. (Some programs do go away when you close the last window, but not the majority of them). 

This can have a big effect on your available memory. For example, I just took a look at the memory on my system in the Activity Monitor (which you'll find in the Utilities folder if you're on 10.5 or 10.6 – I can't remember when they changed the name, but it was called something else before that). One program had been up for about a week – NetNewsWire, my RSS reader (and a pretty good one it is, too, if you are looking for an RSS reader). It was using up 500 MB of RAM – half a gig! I sent it away (with Command-Q, which does completely end a program, just like going to the program's menu and selecting Quit) and started it over – and it came up using 75 MB.

Why the huge difference? As an RSS reader, it goes out to a lot of web sites (I have 130 feeds that I follow) and as I go through the new listings, many have graphics in them. Also, there's quite a few of them that I load up in the internal browser each day. NetNewsWire is caching the graphics (and probably the texts, too) so that if I go back to them, they are instantly available. Safari does this too, caching graphics and web pages (which is why if a page changes you don't always see the change without forcing Safari to refresh the page).

All that caching has to go somewhere. Some caching is done to disk, and some to memory. This is the decision of the programmer, so unless there's something in the preferences that lets you fine-tune what's cached, there's not much you can do about it.

Now, you won't run out of memory (unless you leave a lot of stuff running) because OS X will use swap space, or disk, to move out chunks of memory you haven't used recently (like that photo you were editing but haven't touched in a few minutes) for another program if there's no free memory. Of course, you could run out of free disk, and then you will be out of memory. But unless your disk started out with little free space, that's usually not an issue.

But swapping is slow. You hard drive is many many many times slower than the RAM used by active programs. So it's a good idea to fully Quit a program every so often to free up the memory. I know at first for me this was an odd concept – I've closed all the windows, why is the program still showing in the Dock with the little "running" pip? Well, some programs (like NetNewsWire) can be doing a lot of work behind the scenes, even if there are no windows open.

Leaving something running in the background, like Pages, means if you go back to it a few minutes (or hours) later, it will spring to life immediately (since it is still running and doesn't have to go through all the startup work). If you've got a lot of memory, this can be a good way to easily speed up you machine (and one reason Terry White and I agree that getting as much RAM as you can will be the easiest and often cheapest way to speed up your computer).

But if you are RAM constrained – especially on an older system, where you might be limited to 1 or 2 GB of RAM total – you need to keep a close eye on the Dock, and send away programs you aren't using. Or if it's something like NetNewsWire, send it away every so often to free up memory.

httpv://www.youtube.com/watch?v=iAJ2AoEwDvY

Share →
  • ViewRoyal

    Most Windows users who start using a Mac are used to the “Windows way” of running applications… When you close a document window, the application quits.

    On the Mac, there has always been a distinction between a document (a file created by an application) and the application itself. In actuality they are two different things, and usually are located in different locations on your hard drive. The applications usually reside in the Applications folder, and your documents usually reside in the user’s Document folder.

    It makes sense that closing a document window closes the document, but not the application.

    Imagine for example if you shut down a large application like Adobe Photoshop each time you closed an image document, and then having to launch the application again to open a new image document. That would be a very frustrating process… but not on the Mac, where you have control of the application and documents separately.

  • I would rather choose the behavior in preferences when I first use each application. In some apps, you know you’ll never use more than one window. In others, you’re going to use a ton of them.

  • Patrick

    Relax. Turn off your mind. Float downstream.

    You are way overthinking this. Let OS X do its own memory management, don’t spend your time, energy, and mental focus on helping it. Ask yourself: is there a measurable effect on my interaction with the computer due to memory concerns?

    I don’t believe there is. But if you believe you’re losing time due to this issue, measure your computer’s response after a day of not manually quitting each program. Then quit each program, and immediately rerun your tests.

    You’re spending orders of magnitude more time optimizing your computer’s memory than you save by the optimization.

    Take a deep breath and let it go.

  • Patrick – this isn’t theoretical – I leave my systems up for weeks at a time (I don’t turn them off unless I need to restart). When I look at Activity Monitor because my system is noticeably slow, and I see NO free memory and a lot of swap disk being used, I’m not imagining things. If you’re the type that shuts his computer off every day, you may never see these issues. But I do. I don’t need to “experiment” – I’ve seen the system come back to life after restarting a program.

    Do you really just keep starting things up and never send them away?

  • FYI: The old name was Process Viewer. It got renamed to Activity Monitor in 10.3.

  • Patrick is right. OS X’s Unix roots know how to manage memory well, much better that you or I would by fussing with the Dock and closing applications. And an app can’t hang on to RAM like you suggest, whatever a programmer might do. If it hasn’t been used recently, OS X will move it out to the swap file where it is harmless.

    Excessive swapping isn’t a problem with too many applications being active. It’s too many applications being recently used or, more often, one or two applications grabbing too much memory. Closing applications that are already swapped out won’t fix that problem. You either need more RAM or less RAM-hungry applications.

    I use Windows 7 at one job and OS X at home, and I much prefer the latter way of keeping an application going until I quit it. With Windows I must either endure the reloading of a a big application like Word every time I change documents or play a silly shuffle game, opening File B before I close File A. Yuck!

    This illustrates a major difference in attitudes between Microsoft and Apple. Microsoft regards its users as stupid. They don’t have enough sense to quit an application, so we will do it for them. Apple, on the other hand, regards its users as intelligent. It doesn’t regard a command to close a window (typically Cmd-W) as the same as a command to quit an application (Cmd-Q). If the user wants to do the latter, Apple assumes, he will use the proper command.

  • mike b

    You can also find out what programs are open by command-tab.

  • Mike, I’ve been working on operating systems from mainframes to desktops for over 30 years – I do have some idea what I’m talking about.

    Swapping is *not* always harmless. Apparently, you’ve never heard of “thrashing” – which occurs when you have too many items in memory than the OS can easily swap back and forth to disk. The system slows to a crawl as too many programs compete for memory. Yes, if you can add more memory, you can stave that off – but people with older systems don’t always have that option (you can’t get more than 1 GB into an old eMac, for example).

    Take a look at the memory section of Activity Monitor. Red memory will never be swapped. Do you run Parallels or VMWare? Those are two programs that grab memory and will not allow it to be swapped. This a decision by a programmer.

    In addition, if you are low on disk space, or run into a rouge program, you can get yourself in a situation where you are completely out of memory, including swap – and your system will grind to a halt, telling you to free up some disk.

    I’m not guessing about what I have written about – I have seen it happen, on every system, over the years. Is OS X better at memory management than older systems? Sure. But that doesn’t mean you can just open every program you’ve got and run for months at a time and not have it slow down your system. I’ll wager you guys turn off your systems every night. I don’t. My systems stay up for weeks and sometimes months at a time.

    I also doubt that Microsoft considers it’s users as “stupid” – this article isn’t about “bad” MS and “good” Apple. A programmer can just as easily write programs on Windows that keep running after the last window is closed. I’ve done it. It’s more of a user guideline, not a system requirement. It’s about helping people understand memory management and how in some cases, you should take a hand.

    I’m not saying you need to worry constantly about every byte. In many cases, you don’t need to do much of anything (like for people who turn of their systems daily). But in some cases, programs can eat up a lot of RAM, and even if *you* think they’re doing nothing, they may be running in the background, either preventing swapping to disk or causing excessive swapping.

  • calvin

    Okay for the lighter side of this weeks Beckman Blog. I am impressed with the selection of music to go with the articles. In the words of Darthvader … “Impressive…Most Impressive”.