Home Forums WPF controls Xceed DataGrid for WPF Memory Leak when using BindingList<>

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #22960 |

    Ok, I’ve narrowed down where / when the memory leak is that I had found. I do not know if it is something that I am doing or a problem with the control itself. If it is something in what I am doing, can someone please let me know how to fix the problem on my end.

    The problem is when using a BindingList<> to be able to support the control’s functions since creating new items using InsertionRow does not currently work with ObservableCollection<>. I’ve copied a sample of some offending code below that replicates the problem. The memory from the collection is never freed in Garbage Collection, even though it shouldn’t be referenced any more by the DataGridControl.

    Any help on this would be greatly appreciated.

    If it helps anyone to narrow down the problem, the errors that I am showing in the console output are:

    System.Windows.Data Error: 4 : Cannot find source for binding with reference ‘RelativeSource FindAncestor, AncestorType=’Xceed.Wpf.DataGrid.DataGridControl’, AncestorLevel=’1”. BindingExpression:Path=ViewBindingContext.HorizontalGridLineThickness; DataItem=null; target element is ‘ColumnManagerRow’ (Name=”); target property is ‘BorderThickness’ (type ‘Thickness’)
    System.Windows.Data Error: 4 : Cannot find source for binding with reference ‘RelativeSource FindAncestor, AncestorType=’Xceed.Wpf.DataGrid.DataGridControl’, AncestorLevel=’1”. BindingExpression:Path=ViewBindingContext.HorizontalGridLineBrush; DataItem=null; target element is ‘ColumnManagerRow’ (Name=”); target property is ‘BorderBrush’ (type ‘Brush’)
    System.Windows.Data Error: 4 : Cannot find source for binding with reference ‘RelativeSource FindAncestor, AncestorType=’Xceed.Wpf.DataGrid.DataGridControl’, AncestorLevel=’1”. BindingExpression:Path=ViewBindingContext.HorizontalGridLineBrush; DataItem=null; target element is ‘VirtualizingStackPanel’ (Name=”); target property is ‘ContentBorderBrush’ (type ‘Brush’)
    System.Windows.Data Error: 4 : Cannot find source for binding with reference ‘RelativeSource FindAncestor, AncestorType=’Xceed.Wpf.DataGrid.DataGridControl’, AncestorLevel=’1”. BindingExpression:Path=ViewBindingContext.HorizontalGridLineThickness; DataItem=null; target element is ‘VirtualizingStackPanel’ (Name=”); target property is ‘ContentBorderThickness’ (type ‘Thickness’)

    The sample code to replicate it is as follows:

    <DockPanel x:Name=”uxLayoutRoot”>
    <Button Click=”GarbageCollect” DockPanel.Dock=”Top”>Garbage Collect</Button>
    <Button Click=”LoadNewObject” DockPanel.Dock=”Top”>Load New Object</Button>
    <xcdg:DataGridControl x:Name=”uxGrid” ItemsSource=”{Binding Path=Collection}”>
    <xcdg:DataGridControl.Columns>
    <xcdg:Column FieldName=”Data” />
    </xcdg:DataGridControl.Columns>
    </xcdg:DataGridControl>
    </DockPanel>

    public partial class Window1 : System.Windows.Window
    {
    private MyRootClass _root = new MyRootClass();

    public Window1()
    {
    InitializeComponent();

    Binding binding = new Binding();
    binding.Source = _root;

    uxLayoutRoot.SetBinding(DockPanel.DataContextProperty, binding);
    }

    private void GarbageCollect(object sender, RoutedEventArgs e)
    {
    GC.Collect();
    GC.WaitForPendingFinalizers();
    }

    private void LoadNewObject(object sender, RoutedEventArgs e)
    {
    _root.LoadNewCollection();
    }
    }

    public class MyRootClass : INotifyPropertyChanged
    {
    private BindingList<MySubData> _collection;

    public event PropertyChangedEventHandler PropertyChanged;

    public MyRootClass()
    {
    LoadNewCollection();
    }

    public BindingList<MySubData> Collection
    {
    get
    {
    return _collection;
    }
    set
    {
    _collection = value;

    if (PropertyChanged != null)
    {
    PropertyChanged(this, new PropertyChangedEventArgs(“Collection”));
    }
    }
    }

    public void LoadNewCollection()
    {
    BindingList<MySubData> obj = new BindingList<MySubData>();

    for (int i = 0; i < 100000; i++)
    {
    obj.Add(new MySubData(“sample string of data… one of many…”));
    }

    Collection = obj;
    }

    }

    public class MySubData : INotifyPropertyChanged
    {
    private string _data;

    public event PropertyChangedEventHandler PropertyChanged;

    public MySubData(string data)
    {
    _data = data;
    }

    public string Data
    {
    get
    {
    return _data;
    }
    set
    {
    _data = value;

    if (PropertyChanged != null)
    {
    PropertyChanged(this, new PropertyChangedEventArgs(“Data”));
    }
    }
    }
    }

    Imported from legacy forums. Posted by John (had 6015 views)

    Xceed Support
    Member
    Post count: 5658

    Using your program, I’ve been able to isolate the problem…

    The fix could not make it into version 1.1 (which release is imminent) but will be available in next service release…

    Thank you for reporting this and for providing the repro program.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 285 views)

    User (Old forums)
    Member
    Post count: 23064

    Glad I could help. Great job on the control. I’m loving what it can do. I know 1.1 is due out any time and you said the fix wouldn’t be in that release. How often are the service updates typically released? It would be nice to know roughly how far out that update might be.

    Imported from legacy forums. Posted by John (had 683 views)

    Xceed Support
    Member
    Post count: 5658

    We are typically aiming at releasing service releases every 5 weeks or so…

    This is still depending on several factors like:

    – features being implemented,
    – the amount of critical / high priority bugs,
    – phase of the moon,
    – the alignment of Venus,
    – and a randomly generated number.

    😛

    Seriously, we are aiming on releasing every 5 weeks.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 307 views)

    User (Old forums)
    Member
    Post count: 23064

    Is there any workaround that I would be able to do on my end to get the control to properly release the resources until the official fix is released?

    Imported from legacy forums. Posted by John (had 496 views)

    Xceed Support
    Member
    Post count: 5658

    If you can live with the workaround, yes…

    If you remove any ColumnManagerRow from the FixedHeaders … that should do the trick…

    In fact, you would have to avoid any Row derived class in the “Fixed” regions of the Grid… (Headers and Footers are OK, its just the “Fixed” regions)…

    Alternatly, there is something else that might have chances of success (while I did not try it myself), you could empty your data source and force a complete layout pass (UpdateLayout() ) and then change your ItemsSource.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 721 views)

    User (Old forums)
    Member
    Post count: 23064

    Ok, update. The fix removing any Fixed Header / Footer did work in my app to eliminate the memory leak. While not fit for any ultimate end-users, it does at least allow me to more accurately stress test what I am working on without it grinding the system to a halt after only a few minutes of switching records. This is at least a temporary fix until the updated release comes out. Thanks for your help. It is greatly appreciated.

    I did try the possible alternative of emptying the data source and running UpdateLayout. Unfortunately it does not appear to work (at least not in my app). It was worth a try anyhow.

    Imported from legacy forums. Posted by John (had 428 views)

    Xceed Support
    Member
    Post count: 5658

    OK, thanks for the update concerning the second “wishful” workaround…

    Be assured we are aware of the severity of this issue from an application developper’s standpoint… We are to address that in the next service release.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 238 views)

    User (Old forums)
    Member
    Post count: 23064

    Just in case your missed it, the service release is available : <a href=”http://download3.xceedsoft.com/Packages/3.0.7273.12150/XceedComponents.exe”>http://download3.xceedsoft.com/Packages/3.0.7273.12150/XceedComponents.exe</a&gt;

    It does include a fix to this issue :).

    Imported from legacy forums. Posted by Matt (had 7169 views)

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.