monotouch - Garbage collecting issue with Custom viewbinding in mono touch and mvvmcross -
i have custom calendar command there custom viewbinding. in viewbinding hook events not decoupled right , therefor garbage collecting not completed. in next our custom view binding. can see event hooked in constructor , decoupled in onselecteddate event triggered(the user selects date). hence if take date event decouple right , garbage collected if go back, event still hooked , no garbage collecting performed. thought trigger event null values , and thereby decoulpe event. think there must more clever way accomplish this.
namespace cmsapp.core.binders { public class calendarviewbinding:mvxbasetargetbinding { private calendarview _calendarview; private datetime _currentvalue; public calendarviewbinding(calendarview calendarview) { _calendarview = calendarview; _calendarview.ondateselected+=ondateselected; } protected override void dispose(bool isdisposing) { if(_calendarview!=null) { _calendarview.ondateselected -= ondateselected; _calendarview = null; } base.dispose(isdisposing); } private void ondateselected(object sender, selecteddateeventargs args) { _currentvalue = args.selecteddate; this.firevaluechanged(_currentvalue); _calendarview.ondateselected -= ondateselected; } public override void setvalue(object value) { var date = (datetime)value; _currentvalue = date; _calendarview.selecteddate = _currentvalue; } public override type targettype { { homecoming typeof(datetime); } } public override mvxbindingmode defaultmode { { homecoming mvxbindingmode.twoway; } } } }
any help appreciated :)
it looks me binding correct.
the issue can see unsubscribes event - can't phone call _calendarview.ondateselected -= ondateselected;
twice - don't think problem seeing.
i guess problem not in code using:
either there's bug in binding code in underlying framework using or bug/issue in way using binding or memory leak has nil bindingit's not easy test limited code posted here, simpler if produce simple app reproduces leak seeing. share , might able more feedback.
if believe guesses wrong, thing can suggest switch weakreferences within binding - feels sticking plaster rather cure.
just adding link when release objects in mono touch / mvvmcross
monotouch garbage-collection mvvmcross
No comments:
Post a Comment