Avalon Memory Manager memory leak

I noticed a memory leak in my code. I used the Ants memory profiler to find out where the memory leak occurs from the only operation I perform is switching tabs in my application.

I updated from the extended WPF toolkit 2.0.0.0 → 2.5.0.0, but this did not solve my problem.

here is a graph coming from ants enter image description here

there is a collection exchangechangeventhandler that has 7 instances all located inside obserablecollection<BaseViewerTabItem>

here is part of my code:

 public class ViewerBaseViewModel : ViewModelBase
    {
        protected bool IsViewerMode; // Used to identify if the image was loaded from a file to the viewer mode
        protected ImageManager _imageManager;
        private readonly IMessageBoxService _messageBoxService;
        private readonly ProgressIndicatorViewModel _progressIndicator;           
        protected ImageCollection CurrentImageCollection { get; set; }
        protected int _imageTabCounter = 1;

        private Dictionary<int, List<ImageViewerTabItem>> _groupedImages;

        public ObservableCollection<BaseViewerTabItem> OpenViewers { get; private set; }

The ImageViewerTabItem class is registered in the OpenViewersCollectionChanged event and also cancel it, as you can see

public ImageViewerTabItem(RelayCommand<ImageViewerTabItem> closeTabCommand, RelayCommand<ImageViewerTabItem> duplicateTabcommand, RelayCommand<AttachableItem> attachTabCommand,
            RelayCommand<ImageViewerTabItem> detachTabCommand, RelayCommand ungroupAllCommand, RelayCommand groupAllCommand, ObservableCollection<BaseViewerTabItem> openViewers, Dictionary<int, List<ImageViewerTabItem>> groupedImages)
        {
            _closeTabCommand = closeTabCommand;
            _duplicateTabcommand = duplicateTabcommand;
            _attachTabCommand = attachTabCommand;
            _detachTabCommand = detachTabCommand;
            _ungroupAllCommand = ungroupAllCommand;
            _groupAllCommand = groupAllCommand;
            OpenViewers = openViewers;
            _groupedImages = groupedImages;
            OpenViewers.CollectionChanged += OpenViewersChanged;
        }

public void TearDown()
        {
            OnTabClosed();
            OpenViewers.CollectionChanged -= OpenViewersChanged;
            ImageContentViewModel.TearDown();
        }

here is my xaml code

<Grid>
        <xcad:DockingManager DocumentsSource="{Binding OpenViewers}"
                             x:Name="MainTabControl"
                             LayoutItemTemplate="{StaticResource imageSelectionTemplate}"
                             ActiveContent="{Binding ActiveTabItem, Mode=TwoWay}"
                             DocumentHeaderTemplate="{StaticResource DocumentHeaderDataTemplate}"
                             DocumentTitleTemplate="{StaticResource DocumentTitleDataTemplate}" IsHitTestVisible="True" VerticalContentAlignment="Stretch" VerticalAlignment="Stretch">
            <xcad:LayoutRoot>
                <xcad:LayoutPanel Orientation="Horizontal" >
                    <xcad:LayoutDocumentPane />
                    </xcad:LayoutPanel>
                </xcad:LayoutRoot>

        </xcad:DockingManager>
    </Grid>

Can you suggest where my problem might be?
or how to find a memory leak?
Can Avalon refueling have a memory leak?

+4

Source: https://habr.com/ru/post/1614423/


All Articles