A hack for dealing with the fan/temperature issues in Lion
Lion is more resource-intensive than Snow Leopard and earlier versions, and this is part of the reason for why the temperature gets high and the fan runs more frequently in Lion.
Using the Activity Monitor, I see that after a short time of running after boot-up, more than 25% of my available memory is sitting in the "Inactive" state. This is memory that is released to the OS after applications run, but which is held for a period of time, or until the applications in question restart. This allows those applications to restart a little more quickly, at the cost of preventing other applications from using that memory while it's being held.
After a while, that Inactive memory gets freed, but until it does, that memory is unusable (unless any of the applications which previously held it will restart), and this can cause other running applications to have to swap on and off of disk because of a lack of available memory. This, in turn, causes the system to work harder, which means that the CPU gets hotter and the fan runs more.
In practice, the OS hangs onto that Inactive memory for a very long time, and the resulting ongoing swapping greatly contributes to the persistent and ongoing heat and fan issues. I'm guessing that this is a bug, and that Apple needs to change the logic that is used for freeing up Inactive memory in Lion, so this happens more frequently.
Until (unless?) Apple fixes this problem, I have come up with a hack that will periodically free memory from the Inactive pool if the total within that pool exceeds a specified amount. This gives the memory back to the OS and prevents swapping and a lot of the overheating. As a side effect, new applications might take a little longer to start up, but I find that this delay is barely noticeable, and it's well worth it in terms of improving the temperature and fan issues.
My hack involves a shell script combined with an AppleScript. For those of you who aren't familiar with one or both of these tools, here are detailed instructions for how to set everything up.
Open up the Finder and navigate to your home folder.
Create a sub-folder in your home folder called bin, if one doesn't already exist.
Create a sub-folder in your home folder called Applications, if one doesn't already exist.
Open up Text Edit and select File->New. Then, select Format->Make Plain Text.
In the open Text Edit window, enter the following text exactly as shown (except that you can change the tooMuchMem setting if you want). It's best to copy and paste it into the Text Edit window. Make sure that the #!/bin/bash line is the topmost line of the script, with no blank lines before it, and that the "#!" is in the leftmost column with no spaces before it:
#!/bin/bash
# Number of 4096-byte pages (50000 means 204,800 MB; you can change this) ...
tooMuchMem=50000
oldIFS="${IFS}"
IFS=:
/usr/bin/vm_stat 2>/dev/null \
| while read header mem
do
case "${header}" in
Pages\ inactive)
IFS="${oldIFS}"
mem="$(echo "${mem}" | /usr/bin/sed -e 's/\.//g' -e 's/ *//g')"
[[ ${mem} -gt ${tooMuchMem} ]] && {
echo -n "purging due to ${mem} inactive memory blocks > ${tooMuchMem} ..."
/usr/bin/purge
echo " done"
}
break
;;
esac
done 2>/dev/null
exit 0
Select File->Save...
In the save dialog box, navigate to the bin folder that you created to under your home folder.
Select Unicode (UTF-8) in the Plain Text Encoding box.
Un-check If no extension is provided, use ".txt".
Type releasemen in the Save As box.
Click Save and then quit from Text Edit.
Go to Finder and make sure there is now a file called releasemem in the bin sub-folder of your home folder.
Open Terminal. Type cd followed by the Return key to make sure you are in your home folder. Then, type this follwed by the Return key (it will set up releasemem to be an executable shell script). It's best to copy and paste this line into Terminal and then type the Return key.
chmod +x bin/releasemem
Close Terminal.
Now, open up AppleScript Editor. In the empty window which shows up, enter the following text exactly as shown (except that you can change the delayTime setting, if you want). It's best to copy and paste:
property homeDir : POSIX path of (path to home folder)
property delayTime : 60 (* seconds to wait between retries; you can change this *)
set releasemem to homeDir & "bin/releasemem"
repeat while true
do shell scriptreleasemem
delaydelayTimeend repeat
Click on compile (under the hammer icon), and then select File->Save As...
In the File Format menu in the save-as dialog box, select Application. Un-check all of the Options boxes.
Navigate to the Applications sub-folder of your home folder, and type ReleaseMem.app in the Save As box.
Click Save and then quit from AppleScript editor.
Open up System Preferences->Users & Groups. Select your login name and then click on Login Items.
Click the + (plus sign) button under the list of Login Items. Navigate to the Applications sub-folder of your home folder and select ReleaseMem.app.
Put a check in the box to the left of ReleaseMem.app in the Login Items list.
Now you can exit from System Preferences.
From now on, whenever you log in, the ReleaseMem application will start up. Every 60 seconds -- or whatever you specify within the AppleScript -- it will check whether your Inactive memory exceeds 50,000 blocks (204,800 MB) -- or whatever you specify in the releasemem script. If it exceeds that amount, the memory will be "purged"; i.e., released back to the OS.
I have done this, and I find that my fan hardly ever turns on any more, and that there is plenty of available memory.
I hope this works for you, although YMMV.
.
MacBook Pro, Mac OS X (10.7), Unibody MacBook Pro