SfDataGrid not cleared of memory on WPF

Hi,

On our company's app, we've recently started implementing a WPF app with Xamarin.Forms. Our app uses quite a bit of SfDataGrid with a lot of data in them.

The issue we currently have is that whenever we close a page, the grid and all its components stay in memory and are never released. I've linked in this post a .zip of a sample project with a single grid.

In this sample, if we click on the "Go to list" button, it opens the page with the grid, and then if we click on the Back button, it closes the page and shows the main page again. I've made a few back and forth, and everytime we go back to the main page, around 500 kb have been added. If I remove the grid from the page, the memory usage stays around the same amount. (I've also linked an image with and without the grid to show the differences)

In addition to resolving this issue, I'd also like, if possible, to know if there is a way to solve this issue without updating the grid to a new version.

Attachment: Grid_Issue_170499ec.zip

5 Replies 1 reply marked as answer

KK Karthikraja Kalaimani Syncfusion Team July 24, 2020 11:02 AM UTC

Hi Maxence,

We tested in your sample the reported issue of "SfDataGrid memory leaks in a WPF platform." We noticed the SfDataGrid in OnDisappering method never disposed of. So, only the memory increased in your application. Please refer to the code snippet below to dispose of the Datagrid when navigating to another page.

Code Snippet :

 
public partial class GridPage : ContentPage 
       { 
             public GridPage () 
             { 
                    InitializeComponent (); 
        } 
 
        protected override void OnDisappearing() 
        { 
            base.OnDisappearing(); 
 
            if (this.dataGrid != null) 
            { 
                this.dataGrid.Dispose(); 
                this.dataGrid = null; 
            } 
        } 
    } 


Note : We have checked the Memory leak by using Performance profiler.

Regards,
Karthik Raja
 



MR Maxence Roberge July 24, 2020 02:41 PM UTC

Hello,

I've copied your code snippet as is, but even on my sample app, I still see around 9 000 objects and 300 Kb that are still left behind every time I leave the page. Even with a forced GC collection, the objects still remain.

I've also linked an image with the new results.

Attachment: With_Dispose_be8197b7.zip


KK Karthikraja Kalaimani Syncfusion Team July 27, 2020 08:08 AM UTC

Hi Maxence,

We checked the memory leak by using the Performance profiler and we found there are no objects which are related to SfDataGrid were not present when come back to the normal page. We have attached the tested report for your reference. Please let us know if the SfDataGrid related objects still remain in those 9000 objects in your side?. If the SfDataGrid related objects is remain? please let us know the object details to check it further. Also please tell us how you are testing the memory leak in your side. Since we are using a Performance profiler to check the memory leak in the WPF platform.

Report link : https://www.syncfusion.com/downloads/support/directtrac/general/ze/Report20200727-11582105467324.zip


Regards,
Karthik Raja
 



MR Maxence Roberge July 29, 2020 03:22 PM UTC

Hello again,

As I've said before, the 9000 objects completely disappear whenever I remove the SfDataGrid, which is why I believe they are related to your grid.

Personnally, I use the Diagnostic Tools on Visual Studio to test it. Under the Memory Usage tool, you can take a Snapshot of the memory usage, and if you take a second one, it shows you the difference between the two snapshots It shows how many objects were added and removed from memory, and how much memory is being used.

Some of the objects that remain are specifically objects for the data grid, and others are simply linked to them. I've linked an image which shows some of the objects that remain.

Attachment: KeptObjects_8a7047fc.zip


KK Karthikraja Kalaimani Syncfusion Team July 30, 2020 09:44 AM UTC

Hi Maxence,

If we use diagnostic tools to check memory leak it will not show the accurate objects. We have also checked with Xamarin.Forms.ListView and we saw that listview objects still remains when come back to normal page. So, we suggest you to check the performance in release mode and use performance profiler this will give you results closer to end-user experience.

Regards,
Karthik Raja


Marked as answer
Loader.
Up arrow icon