summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorGrace Kloba <klobag@google.com>2010-04-11 22:53:42 -0700
committerGrace Kloba <klobag@google.com>2010-04-12 08:08:06 -0700
commitf56f68d291ae26ff25db4dc62122692c1dd1f4f9 (patch)
tree0fa20e2708d4130b60ca39eb7053fb1f98fb561c /src/com
parentf49ecd60e2363d414d3ff1d9d1a7d3110d741125 (diff)
downloadpackages_apps_Browser-f56f68d291ae26ff25db4dc62122692c1dd1f4f9.tar.gz
packages_apps_Browser-f56f68d291ae26ff25db4dc62122692c1dd1f4f9.tar.bz2
packages_apps_Browser-f56f68d291ae26ff25db4dc62122692c1dd1f4f9.zip
More aggressively free up the background tabs when
memory is low. Instead of free one tab per onLowMemory, free half of opened tabs as onLowMemory is not called as often as before. Fix http://b/issue?id=2583335
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/browser/TabControl.java65
1 files changed, 36 insertions, 29 deletions
diff --git a/src/com/android/browser/TabControl.java b/src/com/android/browser/TabControl.java
index 4be777d62..7cd2ccbe9 100644
--- a/src/com/android/browser/TabControl.java
+++ b/src/com/android/browser/TabControl.java
@@ -318,7 +318,8 @@ class TabControl {
t.setOriginalUrl(state.getString(Tab.ORIGINALURL));
}
mTabs.add(t);
- mTabQueue.add(t);
+ // added the tab to the front as they are not current
+ mTabQueue.add(0, t);
}
}
// Rebuild the tree of tabs. Do this after all tabs have been
@@ -341,20 +342,22 @@ class TabControl {
}
/**
- * Free the memory in this order, 1) free the background tab; 2) free the
+ * Free the memory in this order, 1) free the background tabs; 2) free the
* WebView cache;
*/
void freeMemory() {
if (getTabCount() == 0) return;
- // free the least frequently used background tab
- Tab t = getLeastUsedTab(getCurrentTab());
- if (t != null) {
- Log.w(LOGTAG, "Free a tab in the browser");
- // store the WebView's state.
- t.saveState();
- // destroy the tab
- t.destroy();
+ // free the least frequently used background tabs
+ Vector<Tab> tabs = getHalfLeastUsedTabs(getCurrentTab());
+ if (tabs.size() > 0) {
+ Log.w(LOGTAG, "Free " + tabs.size() + " tabs in the browser");
+ for (Tab t : tabs) {
+ // store the WebView's state.
+ t.saveState();
+ // destroy the tab
+ t.destroy();
+ }
return;
}
@@ -366,34 +369,38 @@ class TabControl {
}
}
- private Tab getLeastUsedTab(Tab current) {
+ private Vector<Tab> getHalfLeastUsedTabs(Tab current) {
+ Vector<Tab> tabsToGo = new Vector<Tab>();
+
// Don't do anything if we only have 1 tab or if the current tab is
// null.
if (getTabCount() == 1 || current == null) {
- return null;
+ return tabsToGo;
}
- // Rip through the queue starting at the beginning and tear down the
- // next available tab.
- Tab t = null;
- int i = 0;
- final int queueSize = mTabQueue.size();
- if (queueSize == 0) {
- return null;
+ if (mTabQueue.size() == 0) {
+ return tabsToGo;
}
- do {
- t = mTabQueue.get(i++);
- } while (i < queueSize
- && ((t != null && t.getWebView() == null)
- || t == current.getParentTab()));
- // Don't do anything if the last remaining tab is the current one or if
- // the last tab has been freed already.
- if (t == current || t.getWebView() == null) {
- return null;
+ // Rip through the queue starting at the beginning and tear down half of
+ // available tabs which are not the current tab or the parent of the
+ // current tab.
+ int openTabCount = 0;
+ for (Tab t : mTabQueue) {
+ if (t != null && t.getWebView() != null) {
+ openTabCount++;
+ if (t != current && t != current.getParentTab()) {
+ tabsToGo.add(t);
+ }
+ }
}
- return t;
+ openTabCount /= 2;
+ if (tabsToGo.size() > openTabCount) {
+ tabsToGo.setSize(openTabCount);
+ }
+
+ return tabsToGo;
}
/**