| Index: android_webview/native/aw_contents.cc
|
| diff --git a/android_webview/native/aw_contents.cc b/android_webview/native/aw_contents.cc
|
| index 4bdcf7ee2662a29f596dde2c22969756fc4adf9e..5770a07537a6fe2743ab14eecfce29bfb1ba155f 100644
|
| --- a/android_webview/native/aw_contents.cc
|
| +++ b/android_webview/native/aw_contents.cc
|
| @@ -298,6 +298,13 @@ AwContents::~AwContents() {
|
| if (icon_helper_.get())
|
| icon_helper_->SetListener(NULL);
|
| base::subtle::NoBarrier_AtomicIncrement(&g_instance_count, -1);
|
| + // 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);
|
| + }
|
| }
|
|
|
| jint AwContents::GetWebContents(JNIEnv* env, jobject obj) {
|
| @@ -306,15 +313,11 @@ 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);
|
| - }
|
| + java_ref_.reset();
|
| + // We do not delete AwContents immediately. Some applications try to delete
|
| + // Webview in ShouldOverrideUrlLoading callback, which is a sync IPC from
|
| + // Webkit.
|
| + BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this);
|
| }
|
|
|
| static jint Init(JNIEnv* env, jclass, jobject browser_context) {
|
|
|