diff options
author | qqzhou <qqzhou@codeaurora.org> | 2015-03-31 18:31:10 +0800 |
---|---|---|
committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2015-04-13 19:33:47 -0700 |
commit | c74b5c17490e77cff6437eecce6d6130e45992c3 (patch) | |
tree | 3a32c79d3e7400f5f816bf8068485137691495dc | |
parent | 1f01e495a8b5f81fc85d0ecd8e14a03ba30bf333 (diff) | |
download | android_packages_apps_Dialer-c74b5c17490e77cff6437eecce6d6130e45992c3.tar.gz android_packages_apps_Dialer-c74b5c17490e77cff6437eecce6d6130e45992c3.tar.bz2 android_packages_apps_Dialer-c74b5c17490e77cff6437eecce6d6130e45992c3.zip |
Dialer: fix memory leak in DialpadFragment
By MAT tool, we find there exists several PopupMenu
objects after repeating operation "dial 10086 -> hangup"
several times. It's not right, there should exist only
one object of PopupMenu for DialpadFragment. This PopupMenu
object occupies 40 byte but indeed causes memory leak.
The root cause is that we will call onResume() after hangup
every time, onResume will new PopupMenu every time and set its
mDragListener to overflow image button's mOnAttachStateChangeListeners,
this listener references PopupMenu object and causes PopupMenu can not
be released by GC.
We create PopupMenu in onCreate instead of onResume to avoid
this leak.
Change-Id: Id787bc5e23f9d5f86a9fa03536e9ae901e12cb13
-rwxr-xr-x | src/com/android/dialer/dialpad/DialpadFragment.java | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/com/android/dialer/dialpad/DialpadFragment.java b/src/com/android/dialer/dialpad/DialpadFragment.java index 2e2b27d1a..b497f3736 100755 --- a/src/com/android/dialer/dialpad/DialpadFragment.java +++ b/src/com/android/dialer/dialpad/DialpadFragment.java @@ -396,6 +396,13 @@ public class DialpadFragment extends AnalyticsFragment mDelete.setOnLongClickListener(this); } + // Populate the overflow menu in onCreate instead of onResume to avoid PopupMenu's memory leak. + mOverflowMenuButton = mDialpadView.getOverflowMenuButton(); + mOverflowPopupMenu = buildOptionsMenu(mOverflowMenuButton); + mOverflowMenuButton.setOnTouchListener(mOverflowPopupMenu.getDragToOpenListener()); + mOverflowMenuButton.setOnClickListener(this); + mOverflowMenuButton.setVisibility(isDigitsEmpty() ? View.INVISIBLE : View.VISIBLE); + mSpacer = fragmentView.findViewById(R.id.spacer); mSpacer.setOnTouchListener(new View.OnTouchListener() { @Override @@ -709,15 +716,6 @@ public class DialpadFragment extends AnalyticsFragment mSmsPackageComponentName = DialerUtils.getSmsComponent(activity); - // Populate the overflow menu in onResume instead of onCreate, so that if the SMS activity - // is disabled while Dialer is paused, the "Send a text message" option can be correctly - // removed when resumed. - mOverflowMenuButton = mDialpadView.getOverflowMenuButton(); - mOverflowPopupMenu = buildOptionsMenu(mOverflowMenuButton); - mOverflowMenuButton.setOnTouchListener(mOverflowPopupMenu.getDragToOpenListener()); - mOverflowMenuButton.setOnClickListener(this); - mOverflowMenuButton.setVisibility(isDigitsEmpty() ? View.INVISIBLE : View.VISIBLE); - if (getTelephonyManager().isMultiSimEnabled() && MoreContactUtils.shouldShowOperator(mContext)) { if (SubscriptionManager.isVoicePromptEnabled()) { |