Wednesday, 15 June 2011

windows phone 8 - multiple instances of view and view model in memory -



windows phone 8 - multiple instances of view and view model in memory -

we have windows phone 8 application in using mvvm lite having 4 , 5 views , , same number of view models. 1 day observed size of application increasing usage , reaches more 100 mb , crashes.after lot of testing able understand every time navigate view , instance created , stored in memory.it observed instances of view , view model living in memory , increasing space on ram. confirmed same defining finializer on view class , view model , on closing application finializer called same number of times page navigated to. binding datacontext of view respective view model in xaml. 1 of main view has advertisement command , size increases fast if user navigates view multiple times. how resolve issue. unable understand view should destroyed 1 time user presses button, not happening . help much appreciated.

we found solution adding below line of code code behind.

protected override void onnavigatedfrom(navigationeventargs e) { base.onnavigatedfrom(e); messenger.default.unregister(this); if (e.navigationmode == navigationmode.back) { datacontext = null; } }

what doing above unregisterring message handlers page , assigning datacontext null. in our case datacontext assigned in xaml , messenge handlers registered in onnavigatedto event of page. still unclear on navigating page , page object should have died automatically . , should line of code added mvvm lite project pages , if why not mutual practice.

windows-phone-8 mvvm memory-leaks mvvm-light

No comments:

Post a Comment