views:

106

answers:

0

Hi! I have observable collection with some items.

 /// <summary>
    /// The <see cref="Items" /> property's name.
    /// </summary>
    public const string ItemsPropertyName = "Items";

    private ObservableCollection<SomeItem> _items = new ObservableCollection<BrandItem>();

    /// <summary>
    /// Gets the Items property.
    /// </summary>
    public ObservableCollection<SomeItem> Items
    {
        get
        {

            return _items;
        }

        set
        {
            if (_items == value)
            {
                return;
            }

            _items = value;

            // Update bindings, no broadcast
            RaisePropertyChanged(ItemsPropertyName);
        }
    }

and also pagedCollectionView because I have to group items in datagrid

 public const string ItemGroupedPropertyName = "ItemGrouped";

    private PagedCollectionView _itemsGrouped;

    /// <summary>
    /// Gets the ItemSpecificationsGrouped property.
    /// </summary>
    public PagedCollectionView ItemSpecificationsGrouped
    {
        get { return _itemsGrouped; }

        set
        {
            if (_itemsGrouped == value)
            {
                return;
            }

            _itemsGrouped = value;

            // Update bindings, no broadcast
            RaisePropertyChanged(ItemGroupedPropertyName);
        }
    }
    #endregion

in viewmodel constructor I set

 ItemGrouped = new PagedCollectionView(Items);
 ItemGrouped.GroupDescriptions.Add(new PropertyGroupDescription("GroupName"));

and in view a have datagrid that bind ItemsGrouped

<data:DataGrid ItemsSource="{Binding ItemsGrouped}" AutoGenerateColumns="False">
                                    <data:DataGrid.Columns >
                                        <data:DataGridTextColumn  IsReadOnly="True"
                                             Binding="{Binding ItemAttribut1}" Width="*"/>
                                        <data:DataGridTextColumn    IsReadOnly="True"
                                             Binding="{Binding Attribute2}" Width="*" />
                                    </data:DataGrid.Columns>

                            </data:DataGrid>

when i change items in Items (clear and add new) after many times I have a memory leak.. When I remove ItemsSource everything is fine.. So I know that PagedCollectionView causing memory leak but i don't know why. Any idea, please? Or another solution to group items inside datagrid by some property in collection.. Thank you!!