Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I've been noticing that Safari skyrockets in terms of memory usage. I've been getting some results by restarting it, but I'm wondering if there is an app or some easy script to run that would send a growl notification (or some other sort of notification) to inform me that it has reached, let's say 200MB, and then I would know that it might be time to restart it.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

I found someone's brilliant solution to this exact request over on MacHints.

It's a four year old post, but the method should still work.

share|improve this answer
    
Awesome, thanks! –  drury Jun 23 '11 at 21:19

If you will run any "monitoring" program, will consume memory. My Safari after the restart occupiing 128MB RAM, now when writing this reply has 156MB - so 200MB will gain realy soon. I have usually 600+MB Safari and it is not problem (i have 4GB RAM).

Do you really want restart it after 200MB?

You can for example run the next shell script:

#!/bin/bash
mymax=200000       #in kb
checkinterval=60   #in seconds

while :
do
    ops=($(ps axu | grep Safari | grep -v grep))
    [[ ${ops[5]:-0} > $mymax ]] && growlnotify -a "Safari" -m "memory; ${ops[5]}"
    sleep $checkinterval
done

will every minute check your Safary memory usage. When the resident ram usage (rss) exceeds 200 kb the growl message will appear. For this you must have installed the "growlnotify" shell command from the Growl installation image -> Extras.

You can save the above into "safariwarn.command" and double click on it from the Finder. (will run as Terminal.app)

Or, it is possible run as an application what you can make with the Automator.app.

share|improve this answer
    
I agree that 200MB doesn't seem like a lot. Right now mine is hovering just under 1GB. Mind you, I keep a lot of windows open. :) –  ghoppe Jun 23 '11 at 19:10
    
I have a mid 2007 MacBook (2.16GHZ) with 2GB of RAM and routinely run 15 applications simultaneously, so I need as much RAM as I can get and even when I'm not using it Safari just seems to keep grabbing more kicking on fans and stuff. I've already done the gruber trick with Flash, but it still seems to be the most greedy app I run. That's why I have a desire to write this hack. –  drury Jun 23 '11 at 21:17
    
I'd use this solution over applescript as it's far more efficient with RAM and CPU. Once you find your preferred mymax, you can use launchd to start/quit this script anytime Safari stops/quits. Also growlnotify --sticky leaves the alert up until you dismiss it. –  bmike Jun 23 '11 at 23:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.