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

Memory lead with SfDataGrid?

Hello,

I've developed an UWP app where the "Home" page is based on the SfDataGrid. This app allows users to consult and edit forms that are saved locally then to sync them.
But I can see that each time that I navigate from the "Home" page to the "Details" page and come back to the "Home" page, the memory is not released and increases.

I've done some snapshots with the Performance Profiler:
  1. start of the app : "Home" page
  2. navigate to "Details" page
  3. back to "Home" page
  4. navigate to "Details" page
  5. back to "Home" page
Here is the result for "Heap" memory:
Heap
Here is the result for "Managed Heap" memory:
Managed Heap
We can see that the bigger  difference for the "Heap" memory occurs in the last snapshot: +13.46 MB
When I look the details, there a big number of references to the Syncfusion.SfGrid:
Head - snap 5

For the "Managed Heap" memory, it's always in the last snapshot that we get the bigger increase: +1.12 MB
When I look the details, there are 2 references to Syncfusion (sfDrid/Data) that increase more than 600 000 Bytes:
Managed Head - snap5

Is it normal? Would you have any explanation?

Regards,





3 Replies

JG Jai Ganesh S Syncfusion Team February 9, 2017 01:15 PM UTC

Hi Pierre, 
 
We have analyzed your query. In your application whether you are setting the SfDataGrid.Dispose() while navigate to Details page from Home page? if you not setting it in your application then could you please set the Dispose method while navigating the page.  
 
If still you are facing the memory leak issue after setting the Dispose(), then could you please share your application or provide the simple sample to reproduce the issue to us? It will be helpful for us to analyze further. 
 
Regards, 
Jai Ganesh S 
 



PD Pierre-Christophe DUS February 9, 2017 02:02 PM UTC

I had not yet setted the SfGrid.Dispose() when navigating from Home page to Details page. So I've tested and it seems to work.

I've implemented it in OnNavigatedFrom() method like this:
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
// Dispose resources
this.Resources.Clear();
this.Loaded -= FilteringLoaded;
this.sfDataGrid.CurrentCellRequestNavigate -= OnSfDataGridCurrentCellRequestNavigate;
this.sfDataGrid.Dispose();
this.sfDataGrid.ItemsSource = null;

NavigationCacheMode = NavigationCacheMode.Disabled;
base.OnNavigatedFrom(e);
}
Would you have recommandations on the use of Dispose with a ViewModel first approach?


JG Jai Ganesh S Syncfusion Team February 10, 2017 12:08 PM UTC

Hi Pierre,  
The OnNavigateFrom is an override method and we cannot use it from view model. However, you can call the Dispose() using mvvm pattern while navigate to other page by wiring behavior of the page and call Dispose() inside the page Unloaded event like below, 
<i:Interaction.Behaviors> 
        <i:BehaviorCollection> 
            <local:Behaviour /> 
        </i:BehaviorCollection> 
 </i:Interaction.Behaviors> 
 
public class Behaviour : DependencyObject, IBehavior 
{ 
    Page page; 
 
    public DependencyObject AssociatedObject 
    { 
        get 
        { 
            return page; 
        } 
    } 
 
    public void Attach(DependencyObject associatedObject) 
    { 
        page = associatedObject as Page; 
        page.Unloaded += Page_Unloaded; 
    } 
 
    private void Page_Unloaded(object sender, RoutedEventArgs e) 
    { 
        var grid = (page.Content as Grid).Children[0] as SfDataGrid; 
        grid.Dispose(); 
        grid.ItemsSource = null; 
    } 
 
    public void Detach() 
    { 
        page.Unloaded -= Page_Unloaded; 
    } 
} 
 
 
 
Regards, 
Jai Ganesh S 


Loader.
Up arrow icon