We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to reclaim Memory usage?

Hi,

Do we have to set bindingcontext=null or sfdatagrid=null on OnDisappearing event in order to reclaim memory usage  or is it usually automaticly handled? I see something in your samples, you do it as well. 

   protected override void OnDisappearing()
        {
           BindingContext = null;
            Content = null;
            base.OnDisappearing();
            GC.Collect();
        }

4 Replies

PS Pavithra  Sivakumar Syncfusion Team April 19, 2017 02:04 PM UTC

Hi Emil, 
 
Thanks for contacting Syncfusion Support. 
 
We have checked your query. The disposing of mono and native objects are not correctly happening in all the scenarios in Xamarin.Forms. Hence we have manually disposed our controls in the OnDisappearing() override to reclaim the memory efficiently. Hence we recommend you to dispose our controls when the page containing the controls are disposed of.  
 
Regards, 
Pavithra S 
 



SC Shawn Castrianni July 19, 2017 02:38 PM UTC

How do we do that correctly?  OnDisappearing does NOT mean the page is being disposed, it just means it is no longer the top page.  In other words if I have a mainpage on the screen and then I push a detail page on top, it will call the OnDisappearing for the mainPage and the OnAppearing for the detailpage.  In this very common scenario, I would not want to dispose of anything on the mainpage because as soon as the user clicks Back, I will be seeing the mainpage again so I don't want to dispose of it.

Perhaps you are saying for the OnAppearing event to always create the SyncFusion datagrid and the OnDisappearing event to always dispose of the syncfusion data grid.  I suppose that will work, but would be a lot of unnecessary destruction and creation of datagrid as pages are pushed and popped on the Navigation stack.



DF Dave Friedel December 17, 2017 12:54 AM UTC

I agree. Syncfusion needs to resolve this 


AN Ashok N Syncfusion Team December 18, 2017 12:46 PM UTC

Hi Dave, 
 
Thanks for your update. Now it is not mandatory to dispose the custom controls in the OnDisappearing override and create the instances in the OnAppearing override method manually. Earlier there were issues in the framework when navigating between the pages, and hence we had informed to dispose grid in OnDisappearing as a workaround. But now, the disposing of objects is done properly in the Framework itself when the GC is collected and hence the manual disposing of the view will no longer be needed unless you need to handle the memory more efficiently to free up the spaces utilized by your application.  
 
Please let us know if you require any further clarifications.  
 
Regards, 
Ashok 


Loader.
Live Chat Icon For mobile
Up arrow icon