question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DataGrid Memory Leak

See original GitHub issue

Describe the bug DataGrid keeps a NotifyCollectionChangedEventHandler open on Items when Items is bound to a view model even after its removed from logic/visual tree. Memory leak happens when view model is not eligible to be garbage collected. I have a singleton view model that I bind to a new view instance every time the user navigates to the page.

Because of this open handle, DataGrid is never disposed, causing thousands of Shapes.Rectangle instances to survive GC.

To Reproduce

  • Create a view model with an ObservableCollection of any type, populate it with a generous amount of items upon view model construction
  • Create instance of view model that is referenced as a singleton (making it ineligible for garbage collection)
  • Create a view with DataGrid, bind Items to view model’s ObservableCollection, create dummy columns so that rows will be rendered.
  • Create presentation that instantiates a new view for every navigation, DataContext being set to the same view model
  • Navigate between view in question and elsewhere, thereby causing a new view to be instantiated and bound to view model. Repeat this a few times.
  • Observe memory leak

Expected behavior Memory leak does not occur.

Screenshots Screenshot of Instance Retention Graph created using Redgate Ants Profiler. This graph indicates surviving objects AFTER the view has been destroyed and successfully GC’d. Note WindchimeDataGrid is my own inheritance of DataGrid, however it only contains 10 lines of code to modify selection behavior and I’ve recreated this bug with the normal DataGrid.

Also note my view model at the top, which is referenced ultimately as a single instance in my DI Container.

retentionGraph

Desktop : Windows 10,0.19044

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jhimes144commented, Nov 18, 2022

@timunie Thanks for asking! I’m all set, setting the collection to null fixes the issue. I accidently closed with comment, I’ll let you guys do that.

1reaction
adirh3commented, Nov 12, 2022

@jhimes144 I experienced similar issue, and this fixed it - https://github.com/AvaloniaUI/Avalonia/pull/7948 Doesn’t seemed to be backported into 0.10.x, did you check with 11-previews?

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Datagrid] Possibly Memory Leak · Issue #6566 · mui/mui-x
When navigating to and from a page that mounts Datagrid with a large dataset, the total JS heap size grows in size continuously....
Read more >
WPF DataGrid ItemsSource memory leak
I know it's caused by the line DataGrid1.ItemsSource = dt.DefaultView because if I comment it, the memory leak doesn't occur. I've downloaded ...
Read more >
DataGrid - A memory leak occurs after changing a data ...
We researched the issue and found that it occurs because the key field is not specified for the grid. In this case, the...
Read more >
PM48135: memory leak with DataGrid and ...
A memory leak occurs in conjunction with DataGrids and DojoContextMenu components when deploying, running an associated RUI application.
Read more >
Memory leak - Better datagrid for React, Vue, Angular and ...
Hello, i have a problem with the grid in IE 6/7. The grid has some circula references so the IE 6/7 is not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found