mCalendarView
mCalendarView copied to clipboard
Memory leak problem
There has a memory leak problem in MonthFragment.class
I add this code in it.
@Override
public void onDestroyView() {
super.onDestroyView();
if (mAdapter != null)
MarkedDates.getInstance().deleteObserver(mAdapter);
monthData = null;
unbindDrawables(mFragmentView);
}
private void unbindDrawables(View view) {
if (view.getBackground() != null) {
view.getBackground().setCallback(null);
}
if (view instanceof ViewGroup && !(view instanceof AdapterView)) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
unbindDrawables(((ViewGroup) view).getChildAt(i));
}
((ViewGroup) view).removeAllViews();
}
}
Hi there, thanks for raising this issue.
Could you please create a pull request for it? I believe you modified more than above code snippet. To make sure everything is correct at least I need to know what's the proper value of mAdapter
and mFragmentView
.
My guess is mAdapter
is the CalendarAdapter
which used by MonthFragment
. But still, I need your confirm on that.
And, once I modified MonthFragment
I also need to modify MonthExpFragment
, which is added from another pull request.
Thanks again.
Bob.
it because you use Observer to update CalendarAdapter. in CalendarAdapter.class
public CalendarAdapter(Context context, int resource, ArrayList data) {
super(context, resource);
this.data = data;
MarkedDates.getInstance().addObserver(this);
}
but you forget to delete this observer.
it's a simple question, so I don't submit the code.