Since upgrading to 2.2, I was having a problem with the browser eating up my internal memory. I would frequently see the browser using 20 + Mb of DATA....not the cache, so the only way to free it was to clear the data and lose my bookmarks, history and saved passwords. The solution I came up with was to transfer some of my cache files to the sdcard.
I don't intend this to be a definitive "how to", but rather to document the steps I took so that someone else can follow and possibly add on.
First off, to do this, you will need to have your phone rooted. Having busy box installed makes it easier, but isn't 100% necessary. I will write as if busybox is installed.
The files we are concerned with lie in the /data/data directory. So log into the phone through a local terminal, adb or sshd and obtain su. Next change to the /data/data dir
You should see a list of a bunch of dirs...many of which start with "com". These directories hold application data, including the caches for the applications.
Now, lets take a look at how much memory these directories are taking up. try:
if you get an error that 'du is not found' and you have busy box installed, then system aliases have not been configured. You can set a temp one up (will clear when the shell is closed)
alias du='busybox du'
then try the first command again.
DU recursively digs through a directory and adds up the size of all files contained within. If you notice, 'ls -l' only returns the size of files, not directories. The -d1 flag tells the command to only list directories that are 1 level deep. Skipping this flag will the entire directory tree from the current dir down. The '-h' flag says to use "human readable" sizes. This will output directory sizes in MB, KB or B instead of just bytes.
running the command should return a long list that looks somewhat like this:
(note: this is just a sample of the entire output)
According to this, the entire directory contains 11.1M worth of files, and (for example) com.google.android.apps.maps is using 260.0K of space.
So now, take a look through this list. Most of these directories will be small, but you may see some that are pretty big. Before I moved my cache, my browser was taking up 20+ Mb of space.
For the sake of this writeup, I will use the browser.
The browser data is located in com.android.browser, so:
du -d1 -h
This should return something that looks like:
Notice how large the ./cache directory is. This is one of the ones we want to relocate.
Before I go any farther, as far as I know, not everything here can be relocated. Cache data is fairly safe to move because it is truly temporary. If you delete it, it does not affect the operation of the program...the program just starts rebuilding the cache. Maybe one day I'll experiment with moving other things, but right now, moving just the cache freed up enough memory to satisfy me.
Now we need to create an alternate location to store our cache data. I chose /sdcard/cache. So I made some new directories:
Now that we have the alternate locations we want to store our cache data in place (I'll comment on app_thumbnails in a minute), we need to get the application to use this location. Luckily, this is as simple as using a symbolic link.
First off, we need to delete the old cache. So make sure you are in the /data/data/com.android.browser directory
cp webviewCache/* /sdcard/cache/browser/webviewCache/
rm -r webviewCache
now link the directory you made on the sdcard:
ln -s /sdcard/cache/browser/webviewCache webviewCache
Now when the browser goes to store cache info, it writes it to /data/data/com.android.browser/cache/webviewCache, but the symlink transparently redirects that data to the sdcard.
Now, I mentioned the app_thumbnails above...this is another cache directory that I found (in my research) that others have relocated with success. When I did mine, This freed up another 5 or so MB. The procedure is the same to relocate it. Just delete the app_thumbnails directory and replace it with a sym link to the app_thumbnails dir on the sdcard.
After making these changes, lets run du again:
# du -d1 -h
notice 2 things:
First off, my total directory size is now 2.0M....down from 20M before. Also notice that the directories I relocated seem to be gone! Don't worry, this is just because du doesn't follow symlinks by default. So it is only listing the files stored on the internal memory. If you want to see it with the symlinks intact, just add the "-L" flag to du. This file total should not change all that much since most of the dynamic data is now being written to the sdcard and not the internal memory. These terminal dumps I used are actually from my phone about 12 hours after doing this, so the 20M I 'freed' is actually 20M stored on the sdcard.
There are other applications that can benefit from this (maps is one of them), but the browser was by far the largest memory hog I had on my phone, so I haven't played with any others. I will be curious to hear what people have success moving over.