Can you say memory pig? Safari eats 792MB for dinner!

Discussion in 'macOS' started by CristobalHuet, Jul 24, 2009.

  1. CristobalHuet macrumors 65816

    CristobalHuet

    Joined:
    Jan 18, 2008
    Location:
    Montreal
    #1
    I've always been aware of Safari's infernal memory leaks, but this time it reached a whole new level.

    Running 4GB of RAM doing some routine sound cleaning in Sound Studio, Photoshop open, iTunes, Safari, iCal, Adium...the usual, and I'm shocked to see how sluggish my Mac is, it's never in the entire year I had it taken so long to perform regular tasks.

    I fired up Activity Monitor and to my utter HORROR, under the colour palettes next to "Used:", there's a fugly number: 3.86 GB.
    :eek::eek:

    So I sort by Real Mem and there's our exotic friend Safari, towering above all else with a footprint of 792MB. Safari didn't even have 5 tabs open, let alone the number that SHOULD be required to reach such a high level of memory usage. There were 3 tabs open. Three. None of them flash or video heavy, just regular text websites/forums.

    Rule to self: quitting Safari less than the number of times you bash Mac OS X , weekly, will cause severe repercussions. (aka I never quit it).

    Running 10A411 and 4.0.3, in case anyone's wondering.

    Just thought I'd share. :) Wish I had a screenshot before I quit Safari. :(
     
  2. miles01110 macrumors Core

    miles01110

    Joined:
    Jul 24, 2006
    Location:
    The Ivory Tower (I'm not coming down)
    #2
    Virtual memory is not the same thing as physical memory. You should have sorted by RSIZE.
     
  3. pbasser2 macrumors member

    pbasser2

    Joined:
    Jul 14, 2009
    Location:
    Madison, Wisconsin
    #3
    can you explain? what is the difference and what is RSIZE? thanks.
     
  4. Jisuo macrumors 6502

    Joined:
    Dec 4, 2008
    Location:
    Sweden
    #4
    I've experienced the same thing, I noticed things getting slow and fired up Activity Monitor and Safari was using over 1GB of (real) memory. 1 tab open, this forum. I had 5MB free RAM of 4GB.

    That's when I changed back to Firefox. It stays around 150MB forever.
     
  5. CristobalHuet thread starter macrumors 65816

    CristobalHuet

    Joined:
    Jan 18, 2008
    Location:
    Montreal
    #5
    I meant real memory, I apologize.
     
  6. Steve-M macrumors regular

    Joined:
    Jun 12, 2009
    #6
    Just for comparison
    Safari 4.0.2 two tabs open
    63.01 MB Real Memory size.
    424.07 MB Virtual Memory size.
     
  7. dmorgan macrumors member

    Joined:
    Mar 24, 2009
    #7
    I have Safari 4 running with five tabs open.

    According to Activity Monitor it's using 240.88 MB of real memory. I think you may have a problem?
     
  8. gamera~ macrumors member

    Joined:
    Apr 28, 2005
    Location:
    Boston MA
    #8
    I recommend reading this article on memory in OS X, it's quite good and interesting.
     
  9. mackmgg macrumors 65816

    mackmgg

    Joined:
    Nov 2, 2007
    #9
    Now THERES your problem. First, your using a BETA software, expect bugs. Second, its an OUTDATED beta software. Updated to the newest (two newer builds i believe, as one came out today)
     
  10. iMacmatician macrumors 601

    Joined:
    Jul 20, 2008
    #10
    Just for comparison:

    Safari 4 Public Beta (5528.16): 3 windows, 91 tabs, 505 MB real memory, 1.77 GB virtual memory.

    I've never gotten anywhere near 792 MB (unless I open up a really big page in Safari).
     
  11. DoFoT9 macrumors P6

    DoFoT9

    Joined:
    Jun 11, 2007
    Location:
    Singapore
    #11
    just for comparison..

    41 tabs open in 5 seperate windows.

    RSIZE: 629mb, 2.13GB VSIZE
    UPTIME: 10d, 23hr

    10.5.5, Safari Version 3.1.2 (5525.20.1)

    it doesnt bother that its using up so much, OSX easily clears up RAM when it has to :)
     
  12. sammich macrumors 601

    sammich

    Joined:
    Sep 26, 2006
    Location:
    Sarcasmville.
    #12
    Safari chews up memory over time. It really doesn't matter how many tabs you have open at the time, it does matter how many different sites you've loaded up since you started Safari.

    Just quit/open Safari and hit 'History -> Reopen All Windows From Last Session'.
     
  13. sammich macrumors 601

    sammich

    Joined:
    Sep 26, 2006
    Location:
    Sarcasmville.
    #13
    Well, I decided to make this little script for Safari. Just for the lazy people.

    All it does is close Safari and reopen it with the pages you had from before. Plus a handy, if poorly implemented little message at the end of it all. This isn't the most elegant way to do it, but it's the best I can do with my knowledge of AS and google :D You'll need to open "Script Editor" (spotlight it), copy and paste the code below in, and then press run. You can save it as a standalone app from within Script Editor if you like.

    Enjoy.

    Code:
    -- will only work with "Safari" and "Webkit"
    set brwsr to "Safari"
    
    set before_mem to -1
    if my isRunning(brwsr) then
    	set before_mem to my getProcMB(brwsr)
    end if
    
    tell application "System Events" to set open_apps to (get name of every application process)
    if open_apps contains brwsr then
    	tell application brwsr to activate
    	tell application brwsr to quit
    end if
    tell application "System Events" to set open_apps to (get name of every application process)
    set counter to 1
    repeat while open_apps contains brwsr
    	delay 0.3
    	tell application "System Events" to set open_apps to (get name of every application process)
    	set counter to (counter + 1)
    	if (counter) is greater than 30 then
    		display dialog "Safari is taking too long to close, script will end now"
    		break
    	end if
    end repeat
    tell application "System Events" to set open_apps to (get name of every application process)
    tell application brwsr to activate
    
    tell application brwsr to activate
    tell application "System Events"
    	tell process brwsr
    		tell menu bar 1
    			tell menu bar item "File"
    				tell menu "File"
    					click menu item "Close Window"
    				end tell
    			end tell
    			delay 0.1
    			tell menu bar item "History"
    				tell menu "History"
    					click menu item "Reopen All Windows from Last Session"
    				end tell
    			end tell
    		end tell
    	end tell
    end tell
    
    --
    -- below is adapted from code by "NovaScotian" from http://forums.macosxhints.com/archive/index.php/t-64782.html
    --
    
    if my isRunning(brwsr) then
    	set after_mem to my getProcMB(brwsr)
    end if
    
    if before_mem is not equal to -1 then
    	tell application "Safari" to display dialog "You just freed up " & (before_mem - after_mem) & "MB of RAM. Nice work! :D"
    end if
    on isRunning(appName)
    	tell application "System Events" to if exists process appName then return true
    	return false
    end isRunning
    
    to getProcMB(procName) -- as string
    	try
    		return ((last word of (do shell script "/bin/ps -xc -o command,rss | grep " & procName)) as integer) / 1024 -- result of a division will be real
    	end try
    end getProcMB
     
  14. DoFoT9 macrumors P6

    DoFoT9

    Joined:
    Jun 11, 2007
    Location:
    Singapore
    #14
    wow awsome script!! i might just steal it!! hope there are no bugs :p
     
  15. sammich macrumors 601

    sammich

    Joined:
    Sep 26, 2006
    Location:
    Sarcasmville.
    #15
    There shouldn't be any *fingers crossed*. EDIT: yeah I fixed and updated the code above with a few little tidbits.

    Spread the word! (I'm thinking of making a thread about this, waddya say?)
     
  16. CristobalHuet thread starter macrumors 65816

    CristobalHuet

    Joined:
    Jan 18, 2008
    Location:
    Montreal
    #16
    On 10a421, was on 10a411 when the problem happened actually. :D

    And yeah I expect bugs, but come on, that's just redonculous lol
     
  17. Jisuo macrumors 6502

    Joined:
    Dec 4, 2008
    Location:
    Sweden
    #17
    You don't have to restart Firefox, that's why I changed back after using Safari 4 since beta -> 4.0.1
     

Share This Page