Limit memory for Safari?

Is there a way to limit memory usage of Safari?


This morning I found my system unresponsive because one Safari process had used all available memory and disk space (for swap). The screen was locked, mouse movements only started registering after about a minute and the keyboard was unresponsive as well. I waited for several minutes to no avail.


I logged in remotely using ssh on the ipad and noticed that a Safari process was using around 40GB of memory; which is pretty much all of the 8GB of internal memory and the about 35GB of free disk space I normally have. In the end I had to hard reboot the machine, as even sudo shutdown -r now didn't shut it down...


To the point, that was an insane amount of memory usage and realistically anything over 2GB would be an indication of a problem on a page already. Can I somehow limit Safari processes to, say, 2GB of memory?


PS: I tried killing the Safari process with the kill command, both with and without sudo, but the process stayed. Is there some other method of killing it from the command line?


PS2: Apparently there is some javascript world-clock out there that's included in some pages I visit that causes this. I haven't been able to pinpoint the exact source of the problem.

Mac mini (Late 2012), OS X Mavericks (10.9)

Posted on May 10, 2016 3:09 AM

Reply
5 replies

May 10, 2016 4:50 AM in response to Dalroi123

All web browsers even on Windows I find to leak memory like the proverbial sieve. The more windows or tabs you have open and the longer you leave it running the more memory is used and 'leaked'.


I am not aware of a means of defining a limit for a specific individual program in terms of memory use.


To kill Safari via a terminal session using the kill command you would first need to find its PID (Process ID), this would involve running the ps command, to help you out I have included a grep command to filter it to the single process you are looking for.


ps -x | grep "Safari.app"


This will actually list two results, one the actual Safari process, the other the above command itself which of course contains Safari.app in the command. You should then be able to do


sudo kill -9 1234


by substituting the correct PID number.


However there is another perhaps easier solution which is not to use the kill command but instead to use the related killall command as follows.


sudo killall -c Safari

May 10, 2016 4:50 AM in response to John Lockwood

Some leakage wouldn't bother me, but this particular case can easily be witnessed in Activity Monitor when it takes off (which appears to be kind of random); the process normally uses about 100MB, but doubles or triples in memory usage with every refresh (every 5s) of Activity Monitor!

I'm basically trying to bandaid this behaviour by stopping Safari in its tracks when this does happen. Better to have Safari break than the entire system. I'm still hoping for some way to do that...

It also appears that (AFAIK, unlike several other UNIX-based OS's) OS X doesn't limit user process resources so that kernel/core/system processes can always continue, even when resources are low. Otherwise the system would probably not have locked up like it did - although ssh still worked (and with good responsiveness even)! Curious...


I did try variations on the commands you suggested while logged in through ssh this morning, but they didn't work. I suppose the system had already gotten in a wedged state due to lack of resources, or at least Safari had become unkillable. Anyway, thanks for confirming that those commands should have worked.


BTW, I noticed while testing just now that you don't need sudo to kill Safari. That makes sense when you're logged in under the same account, they are your processes after all.

May 10, 2016 7:34 AM in response to cdhw

To clarify "kind of random": It is kind of random in time for at least one specific web site, not random in which web site I visit. The act of refreshing the website often (say 1 out of 3 refreshes) starts the memory churning away. Oddly, the website has a refresh button as well that uses AJAX to update the most relevant content, which does not cause this, so it's probably related to one of the asides (either the Disqus forum or the world clock, both external scripts).

When it's starting to run away: Copying the URL, closing the tab, opening a new tab and finally pasting the URL usually fixes the behaviour. Sometimes this happens after a while all by itself (like last night), presumably because something on the web site executes a reload.


I don't see much of interest in the EtreCheck report, but here it is:


EtreCheck version: 2.9.12 (265)

Report generated 2016-05-10 16:18:51

Download EtreCheck from https://etrecheck.com

Runtime 2:58

Performance: Excellent


Click the [Support] links for help with non-Apple products.

Click the [Details] links for more information about that line.

Click the [Check files] link for help with unknown files.


Problem: Beachballing

Description:

Safari runs out of memory


Hardware Information:

Mac mini (Late 2012)

[Technical Specifications] - [User Guide] - [Warranty & Service]

Mac mini - model: Macmini6,1

1 2,5 GHz Intel Core i5 CPU: 2-core

8 GB RAM Upgradeable - [Instructions]

BANK 0/DIMM0

4 GB DDR3 1333 MHz ok

BANK 1/DIMM0

4 GB DDR3 1333 MHz ok

Bluetooth: Good - Handoff/Airdrop2 supported

Wireless: en1: 802.11 a/b/g/n


Video Information:

Intel HD Graphics 4000

Cinema HD 1920 x 1200


System Software:

OS X El Capitan 10.11.4 (15E65) - Time since boot: about 7 hours


Disk Information:

APPLE HDD HTS545050A7E362 disk0 : (500,11 GB) (Rotational)

EFI (disk0s1) <not mounted> : 210 MB

Macintosh HD (disk0s2) / : 499.25 GB (35.16 GB free)

Recovery HD (disk0s3) <not mounted> [Recovery]: 650 MB


USB Information:

Apple, Inc. IR Receiver

Apple Inc. BRCM20702 Hub

Apple Inc. Bluetooth USB Host Controller

Logitech USB Receiver

Apple Computer, Inc. Apple Cinema HD Display

Razer Razer Orbweaver

Apple Inc. iPhone

CM Storm Quickfire Pro Ultimate 6 key

Seagate Expansion Desk 4 TB

EFI (disk1s1) <not mounted> : 315 MB

TimeMachine (disk1s2) /Volumes/TimeMachine : 1.00 TB (6.32 GB free)

Storage (disk1s3) /Volumes/Storage : 3.00 TB (2.21 TB free)

MediaTek Inc MT1806

Apple Inc. iPad


Thunderbolt Information:

Apple Inc. thunderbolt_bus


Gatekeeper:

Mac App Store and identified developers


Unknown Files:

/Library/LaunchDaemons/org.macports.gkrellm.plist

One unknown file found. [Check files]


Kernel Extensions:

/Library/Application Support/VirtualBox

[loaded] org.virtualbox.kext.VBoxDrv (5.0.16 - 2016-03-22) [Support]

[loaded] org.virtualbox.kext.VBoxNetAdp (5.0.16 - 2016-03-22) [Support]

[loaded] org.virtualbox.kext.VBoxNetFlt (5.0.16 - 2016-03-22) [Support]

[loaded] org.virtualbox.kext.VBoxUSB (5.0.16 - 2016-03-22) [Support]


/Users/xxx/Downloads (original)/LCC Installer.app

[not loaded] com.Logitech.Control Center.HID Driver (3.5.1 - SDK 10.0 - 2011-11-04) [Support]


System Launch Agents:

[not loaded] 9 Apple tasks

[loaded] 147 Apple tasks

[running] 82 Apple tasks


System Launch Daemons:

[not loaded] 40 Apple tasks

[loaded] 157 Apple tasks

[running] 93 Apple tasks


Launch Agents:

[loaded] com.oracle.java.Java-Updater.plist (2013-06-07) [Support]

[running] net.culater.SIMBL.Agent.plist (2009-10-26) [Support]

[not loaded] org.freedesktop.dbus-session.plist [Support]

[loaded] org.macosforge.xquartz.startx.plist (2014-08-11) [Support]


Launch Daemons:

[loaded] com.adobe.fpsaud.plist (2016-04-05) [Support]

[loaded] com.equinux.VPNTracker7.agent.plist (2013-12-18) [Support]

[loaded] com.oracle.java.Helper-Tool.plist (2013-06-07) [Support]

[loaded] org.firebird.gds.plist (2015-04-26) [Support]

[not loaded] org.freedesktop.dbus-system.plist [Support]

[loaded] org.macosforge.xquartz.privileged_startx.plist (2014-08-11) [Support]

[not loaded] org.macports.gkrellm.plist [Support]

[not loaded] org.virtualbox.startup.plist (2016-03-22) [Support]


User Launch Agents:

[loaded] com.google.keystone.agent.plist (2016-03-02) [Support]

[not loaded] org.virtualbox.vboxwebsrv.plist (2016-03-22) [Support]


User Login Items:

iTunesHelper Application (/Applications/iTunes.app/Contents/MacOS/iTunesHelper.app)


Other Apps:

[running] org.vim.MacVim.56352

[loaded] 391 Apple tasks

[running] 209 Apple tasks


Internet Plug-ins:

iPhotoPhotocast: 7.0 (2009-03-13)

FlashPlayer-10.6: 21.0.0.213 - SDK 10.6 (2016-04-09) [Support]

net.juniper.DSSafariExtensions: Unknown (2014-03-13) [Support]

QuickTime Plugin: 7.7.3 (2016-04-21)

Flash Player: 21.0.0.213 - SDK 10.6 (2016-04-09) Outdated! Update

Default Browser: 601 - SDK 10.11 (2016-04-22)

Silverlight: 3.0.40818.0 (2009-08-18) [Support]

JavaAppletPlugin: Java 8 Update 91 build 14 (2016-05-04) Check version


Safari Extensions:

HD quality for YouTube™ - James Fray - http://add0n.com/youtube-hd.html (2015-03-31)

ClickToFlash - Marc Hoyois - http://hoyois.github.com/safariextensions/clicktoplugin/ (2015-11-28)

Save to Pocket - Read It Later, Inc. - http://getpocket.com/ (2015-11-05)

TinEye - TinEye - https://tineye.com (2015-11-28)

Ghostery - GHOSTERY, Inc. - https://www.ghostery.com/ (2016-03-13)


3rd Party Preference Panes:

Flash Player (2016-04-05) [Support]

Java (2016-05-04) [Support]

MenuMeters (2014-05-06) [Support]


Time Machine:

Skip System Files: NO

Mobile backups: OFF

Auto backup: YES

Volumes being backed up:

Macintosh HD: Disk size: 499.25 GB Disk used: 464.08 GB

Destinations:

TimeMachine [Local]

Total size: 1.00 TB

Total number of backups: 115

Oldest backup: 07/11/14 0:50

Last backup: 10/05/16 15:51

Size of backup disk: Too small

Backup size 1.00 TB < (Disk used 464.08 GB X 3)


Top Processes by CPU:

8% WindowServer

7% kernel_task

6% com.apple.WebKit.WebContent(18)

1% Transmission

1% com.apple.WebKit.Networking


Top Processes by Memory:

1.09 GB com.apple.WebKit.WebContent(18)

901 MB kernel_task

451 MB softwareupdated

221 MB mdworker(12)

197 MB Safari


Virtual Memory Information:

1.56 GB Free RAM

6.44 GB Used RAM (3.10 GB Cached)

0 B Swap Used


Diagnostics Information:

May 10, 2016, 08:38:44 AM Self test - passed

May 11, 2016 5:36 PM in response to Dalroi123

Similar things happening to me as well. I just had a runaway Safari process for a wikipedia page. And as I know (or at least think I do) Wikipedia doesn't exactly plaster weird banner ads or flash videos on their pages.


User uploaded file


I think ~10 GB is a bit much for a page of text. But as you said, for me it happens seemingly randomly with different pages. I keep expecting whatever bug to be fixed in new versions of OS X and/or Safari but no luck.


I do share Ghostery with your Safari extensions (the only other I'm using is LastPass).

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Limit memory for Safari?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.