DateTimePicker memory leak

Open
#1,742 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
38/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp
Domain
desktop

Research direction

Start by reproducing the leak with the provided MainWindow/MyWindow example and repeated DateTimePicker window creation and closure. Inspect the DateTimePicker event subscriptions added around version 4.4.0 and verify that closing or removing the control no longer retains it in memory.

Written by the indexing model from the issue text.

Description

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

Dominant language
C#
Stars
4.2k
Forks
912
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from xceedsoftware/wpftoolkit

All issues in xceedsoftware/wpftoolkit

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.