SlideDateTimePicker icon indicating copy to clipboard operation
SlideDateTimePicker copied to clipboard

SlideDateTimeDialogFragment.mListener cause memory leak

Open fishboil opened this issue 10 years ago • 3 comments

hi, when i use SlideDateTimePicker in my custom view,it will cause the activity who use this custom view ,in the activity's onDestory method i set the custom view's listener null, but still leak,dou you know how to fix this problem? qq 20150806111943

fishboil avatar Aug 06 '15 03:08 fishboil

A quick check using leakcanary reveals that

public static SlideDateTimeDialogFragment newInstance(SlideDateTimeListener listener, Date initialDate, Date minDate, Date maxDate, boolean isClientSpecified24HourTime, boolean is24HourTime, int theme, int indicatorColor)

because it has

private static SlideDateTimeListener mListener;

remove this static newInstance(...){...} and use

Create a new instance of SlideDateTimeDialogFragment

SlideDateTimeDialogFragment dialogFragment = new SlideDateTimeDialogFragment();

    // Store the arguments and attach the bundle to the fragment
    Bundle bundle = new Bundle();
    bundle.putSerializable("initialDate", initialDate);
    bundle.putSerializable("minDate", minDate);
    bundle.putSerializable("maxDate", maxDate);
    bundle.putBoolean("isClientSpecified24HourTime", isClientSpecified24HourTime);
    bundle.putBoolean("is24HourTime", is24HourTime);
    bundle.putInt("theme", theme);
    bundle.putInt("indicatorColor", indicatorColor);
    dialogFragment.setArguments(bundle);`

while creating dialog from SlideDateTimePicker.show()

public void setmListener(SlideDateTimeListener mListener) { this.mListener = mListener; }

KishorFlutter avatar Jun 16 '16 05:06 KishorFlutter

same leak question

kong-jing avatar Jan 18 '17 09:01 kong-jing

solve this problem:

at SlideDateTimeDialogFragment ,add mListener = null;

    public void onDestroyView()
    {
        // Workaround for a bug in the compatibility library where calling
        // setRetainInstance(true) does not retain the instance across
        // orientation changes.
        if (getDialog() != null && getRetainInstance())
        {
            getDialog().setDismissMessage(null);
        }
        mListener = null;
        super.onDestroyView();
    }

kong-jing avatar Jan 19 '17 06:01 kong-jing