Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTimePicker memory leak #1742

Open
hacpatb opened this issue Apr 10, 2023 · 4 comments
Open

DateTimePicker memory leak #1742

hacpatb opened this issue Apr 10, 2023 · 4 comments

Comments

@hacpatb
Copy link

hacpatb commented Apr 10, 2023

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

@XceedBoucherS
Copy link
Collaborator

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

@hacpatb
Copy link
Author

hacpatb commented Apr 12, 2023

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.

@XceedBoucherS
Copy link
Collaborator

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.

@zhongruijia
Copy link

zhongruijia commented Dec 22, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants