From 0fb2f2bd009a6cfdba5ccab6a08f91d379d07d10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E5=87=AF=E4=BC=A6?= Date: Wed, 25 May 2016 10:15:03 +0800 Subject: [PATCH] Fix the memory leak in TetherSettings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://code.google.com/p/android/issues/detail?id=210848 We need to close the bluetooth adapter's profile proxy in OnDestroy method, or it will cause TetherSettings object to be held and won't release. And finally it will cause OOM issue. Change-Id: Id7667f751697c8ef9fccaaabfed28a91d4fa4960 Signed-off-by: 宋凯伦 --- src/com/android/settings/TetherSettings.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/com/android/settings/TetherSettings.java b/src/com/android/settings/TetherSettings.java index a0cd4daa1c4..78b93c67b55 100644 --- a/src/com/android/settings/TetherSettings.java +++ b/src/com/android/settings/TetherSettings.java @@ -182,6 +182,16 @@ public class TetherSettings extends SettingsPreferenceFragment com.android.internal.R.array.config_mobile_hotspot_provision_app); } + @Override + public void onDestroy() { + BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); + BluetoothProfile profile = mBluetoothPan.getAndSet(null); + if (profile != null && adapter != null) { + adapter.closeProfileProxy(BluetoothProfile.PAN, profile); + } + super.onDestroy(); + } + @Override public void onSaveInstanceState(Bundle savedInstanceState) { savedInstanceState.putInt(TETHER_CHOICE, mTetherChoice);