Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c74b5c17 authored by qqzhou's avatar qqzhou Committed by Gerrit - the friendly Code Review server
Browse files

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
parent 1f01e495
Loading
Loading
Loading
Loading
+7 −9
Original line number Diff line number Diff line
@@ -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()) {