SpongeBobSun / mCalendarView

Customizable & Shrinkable Calendar Widget for Android
Apache License 2.0
243 stars 73 forks source link

Memory leak problem #17

Open HeartBeat2333 opened 8 years ago

HeartBeat2333 commented 8 years ago

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();
    }
}
SpongeBobSun commented 8 years ago

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.

HeartBeat2333 commented 8 years ago

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.