How to overcome a massive memory leak in OS X

ActivityMonitorIconXWhen programs perform tasks on OS X and other platforms, chunks of memory are allocated for their needs, but these should be relinquished when the task is done. If not, then a memory leak may occur, where progressively more memory is reserved (sometimes at a rapid rate), until the system cannot allocate anymore and is strained for resources. When this happens, the entire system may run slow, pause, or hang and require a forced restart. Unfortunately there is little you can do as an end-user to prevent a memory leak, but with quick identification you can knock out a program that is causing one, before it starts affecting the entire system.

Memory management has always been a meticulous frustration for programmers to both implement and track in their code, and Apple has taken great efforts to centralize this and keep less on the shoulders of developers. However, underneath all of Apple’s code there is still the requirement for memory management somewhere, so if a bug exists, then some nuance handling of code can still result in a memory leak.

Identifying a memory leak over a process simply using a large amount of memory under normal operation can be difficult, but there are a few tell-tale signs. First, it helps to know the normal memory load of most programs on your Mac. To do this, keep Activity Monitor open and sort the list of processes by Memory. Then see which are using most, and the amount they use under normal operation.

If any process begins to climb up the list without stopping, then keep an eye on it. This is generally normal behavior, especially as you use your system; however, if this continues to where the process is at the top of the list, with its Memory footprint continuing to climb, then this may be fair indication that a memory leak is occurring.

This type of judgement can be difficult, but if memory management does get out of hand to the point where it may destabilize the system, then you will see a few tell-tale signs:

Unused programs closing

If you have some programs open but are not using them, then OS X may shut them down to free up resources for the ones you are using. This feature is called Sudden Termination, and can be hard-coded into programs by developers. When this is used, the only indication it has happened is the program will disappear from the Dock. This may repeat if you re-open the program and then change to another so the opened one is put in the background.

Force-quit window showing low application memory

The force-quit window may show up, claiming you are out of memory and showing applications being paused.

This feature being used does not mean you have a memory leak, but indicates your Mac is low on memory and is making accommodations. If you see this, then it is a good time to open Activity Monitor and see what programs are using the most memory.

Out of Memory errors

If this happens, you will see a system warning display that mentions a program or the system is out of memory. This usually means the system’s virtual memory (the management system that collects all hardware capabilities and presents them as usable memory space for programs) is pushed to its limit and can no longer organize hardware capabilities to accommodate the tasks you are running.

The Force-Quit window suddenly appearing

When the system is dangerously low on resources, OS X will display the force-quit window, which may state the system is out of memory, and which also may show applications in a paused state. This is a last ditch effort by OS X to keep the system running in the face of this memory error, and means you may have only a short time before the memory leak overtakes the system and causes an entire system freeze.

Red processes in Activity Monitor or the Force-Quit window

In the force-quit window, any paused processes or those not responding will be displayed in red; however, this will not tell you what processes may be causing the issue at hand. To do this, return to the Activity Monitor utility, where you can list the processes by memory usage, and determine which are taking up your system’s memory. You can then select these processes and force-quit them to clear the problem. Note that if you are seeing a number of “Safari Web Content” processes that are showing problems, first try force-quitting Safari itself before acting on these individually. This should close all of the Web Content processes that are running within Safari.

Memory leak in OS X

A series of paused processes in Activity Monitor that are using a huge amount of memory (notice Mail at the top of the list, using 52GB of memory) suggest a massive memory leak, as opposed to another error like an application hang.

Overall, memory leaks are as old as computer programming itself, and while there are massive improvements to the way memory is handled, and while such bugs should be at a minimum, they are inherent to computers and may happen for numerous reasons. To tackle them when they happen in OS X, the above procedures will work, but there is ultimately no way to prevent them. Your best bet for prevention is to simply keep your software up to date, and notify developers if you have experienced what you think is a memory leak, so a patch can help prevent it from being an issue in the future.

4 thoughts on “How to overcome a massive memory leak in OS X

  1. James

    “… notice Mail at the top of the list, using 52GB of memory) suggest a massive memory leak …”

    Maybe. You should add Real Mem and Purgeable Mem to your columns to see what is really going on. While 52 GB of virtual memory seems high, depending on if that memory is sparsely distributed then it may not actually be using much real memory.

    Your kernel _task using almost 10 GB is much more likely to be a problem. Do you have a lot of third party kernel extensions?

    1. Topher Kessler Post author

      Kernel_Task’s memory footprint will increase as other programs demand more memory. In normal circumstances it should only use about 10% of your system’s memory, but its VM footprint will change based on how much memory is being allocated to other programs. In situations of high demand such as a memory leak, you will likely see kernel_task balloon in VM usage as well.

      For some computational programs, a 52GB VM footprint may not be uncommon, and simply require a Mac with ample RAM to accommodate this demand, but Mail is definitely not one of these programs. 😉

  2. zenzo

    I’ve never found anyone with a solution to this – But Please If there Is anyone out there to help us with this kind of problem, My Boss just told me to buy the new Apple Mac Pro to replace this one that he bought 2 months back just coz of this problem….. somebody help…. Where Is STEVE JOBS WHEN YOU NEED HIM!!!! – (I’ve tried all from Activity Monitor, To Tools, Fan Utilities etc, Creating extra 100gig space, but no solution, I had installed bootcamp windows 7 and power went off whilst I was uninstalling it…. then 2 days later BOOOM!…this happens and it’s been a week now, and counting…..whew!!! can’t even sleep coz my jobs is on the line here….. – I did install third party softwares however and have since deleted them all (I’m in video, graphics and I guess somebody would give me some ideas……) THANKS!

    1. random mouse (@anoynamouse)

      What a Turd…as if Jobs would even know of this issue to solve it if he’s was alive!

Comments are closed.