SlideDateTimePicker
SlideDateTimePicker copied to clipboard
SlideDateTimeDialogFragment.mListener cause memory leak
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?

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; }
same leak question
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();
}