xceedsoftware/wpftoolkit

DateTimePicker memory leak

hacpatb opened this issue · 4 comments

Found this leak when update from 4.0.1 to 4.5.0. I looked at the code and found added some event in version 4.4.0 for this element.
If you open and then close window or remove element with dtp one of event don't detach and dtp remains in memory.
We can repeat this. Create window with button, on button click open new window with dtp, close window and repeat this 10-100 times.
.NET Framework 4.7.2

<Window x:Class="TestMemoryLeak.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:TestMemoryLeak"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Button Width="100"
                Height="200"
                Content="Push me"
                Click="ButtonBase_OnClick"/>
    </Grid>
</Window>
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
    {
        var mw = new MyWindow();
        mw.Show();
    }
<Window x:Class="TestMemoryLeak.MyWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
        mc:Ignorable="d"
        WindowStyle="ToolWindow"
        Title="Window" Height="100" Width="100">
    <Grid>
        <xctk:DateTimePicker Height="Auto"
                             VerticalContentAlignment="Center"
                             FontSize="15"
                             Padding="0,-2,0,0"
                             Format="Custom"
                             FormatString="dd MMMM yyyy"
                             AutoCloseCalendar="True"
                             ClipValueToMinMax="True"
                             TimePickerVisibility="Collapsed"
                             Background="Transparent" />

    </Grid>
</Window>

Screenshot 2023-04-10 165537

Hello,
Can you confirm that this is happening only in v4.4 and over ?
Do you have more details ?
Thank you

Hello, Can you confirm that this is happening only in v4.4 and over ? Do you have more details ? Thank you

Hi! Yes, this case reproduced on v4.4 and over. I tested version 4.3 and dotMemory don't show event handler leak for this element.

Details: Windows 10(19043.1415), .Net framework 4.7.2, VS 2022(17.5.4), but i think it isn't important.
For reproduce you can create empty wpf project for net framework (may be not only for .net), install nuget package v4.4 or v4.5 from repository. Then look at previous comment, create window with dtp and open-close that window several times.

Hi,
I can confirm this happens in v4.4 and over.
I just made a fix related to this.
It will be part of v4.7.

Thank you for pointing this out.