Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1999)

Unified Diff: android_webview/native/aw_contents.cc

Issue 23888003: Free memory when the last WebView instance is destroyed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adding comment Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: android_webview/native/aw_contents.cc
diff --git a/android_webview/native/aw_contents.cc b/android_webview/native/aw_contents.cc
index 82100be08d15eba2b17a77a6708e7f76a1588fd7..a00c1fe96a8b94f1284a8787aa4c94e26dcbc830 100644
--- a/android_webview/native/aw_contents.cc
+++ b/android_webview/native/aw_contents.cc
@@ -27,6 +27,7 @@
#include "base/atomicops.h"
#include "base/bind.h"
#include "base/callback.h"
+#include "base/memory/memory_pressure_listener.h"
#include "base/message_loop/message_loop.h"
#include "base/pickle.h"
#include "base/strings/string16.h"
@@ -250,6 +251,14 @@ jint AwContents::GetWebContents(JNIEnv* env, jobject obj) {
void AwContents::Destroy(JNIEnv* env, jobject obj) {
delete this;
+
+ // When the last WebView is destroyed free all discardable memory allocated by
+ // Chromium, because the app process may continue to run for a long time
+ // without ever using another WebView.
+ if (base::subtle::NoBarrier_Load(&g_instance_count) == 0) {
+ base::MemoryPressureListener::NotifyMemoryPressure(
+ base::MemoryPressureListener::MEMORY_PRESSURE_CRITICAL);
+ }
}
static jint Init(JNIEnv* env, jclass, jobject browser_context) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698