wpftoolkit icon indicating copy to clipboard operation
wpftoolkit copied to clipboard

Avalon docking manager memory leak

Open ABHIYANSHU opened this issue 4 years ago • 0 comments

I have noticed a memory leak in my code I used Ants memory profiler to see where is the memory leak coming from the only operation I'm doing is switching tabs in my application.

I have upgraded from WPF extended tool kit 2.0.0.0 -> 2.5.0.0 but this didn't solve my problem

here is the graph coming out from ants

image

there is an collectionchangedeventhandler which has 7 instances everything is located inside an 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; }**

I have noticed a memory leak in my code I used Ants memory profiler to see where is the memory leak coming from the only operation I'm doing is switching tabs in my application.

I have upgraded from WPF extended tool kit 2.0.0.0 -> 2.5.0.0 but this didn't solve my problem

here is the graph coming out from ants enter image description here

there is an collectionchangedeventhandler which has 7 instances everything is located inside an 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 class ImageViewerTabItem register to the OpenViewersCollectionChanged event and also unregister from 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

    </xcad:DockingManager>
</Grid>

Can you suggest where my problem could be? or how to find the memory leak? Can Avalon dock have a memory leak?

ABHIYANSHU avatar May 04 '21 03:05 ABHIYANSHU