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

DataContext not getting GC'd/Finalized #12123

Closed
timunie opened this issue Jul 10, 2023 Discussed in #12109 · 6 comments
Closed

DataContext not getting GC'd/Finalized #12123

timunie opened this issue Jul 10, 2023 Discussed in #12109 · 6 comments

Comments

@timunie
Copy link
Contributor

timunie commented Jul 10, 2023

Discussed in #12109

Originally posted by nic547 July 9, 2023
Using the Avalonia .NET Core template, updating to Avalonia11 and editing the mainWindow like following:

public partial class MainWindow : Window
{

    public MainWindow()
    {
        DataContext = new ViewModel();
        InitializeComponent();
    }

    private void Button_OnClick(object? sender, RoutedEventArgs e)
    {
        new MainWindow().Show();
    }

    private void Button_GC_Click(object? sender, RoutedEventArgs e)
    {
        GC.Collect();
    }
}

public class ViewModel
{
    ~ViewModel()
    {
        Debug.WriteLine("Finalized called");
    }

    private readonly byte[] someData = new byte[65536];

}
<Window xmlns="https://github.com/avaloniaui"
        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"
        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
        x:Class="AvaloniaApplication1.MainWindow"
        Title="AvaloniaApplication1">
    <StackPanel>
	    <Button Click="Button_OnClick">Open New Window</Button>
        <Button Click="Button_GC_Click">GC</Button>
	</StackPanel>  
</Window>

After opening and closing new windows, I cannot observe the "ViewModel" getting finalized. Additionally a Memory Snapshot (VS) will reveal as many Instances of the ViewModel as Windows were opened, despite only one being open.

Is there something I need to do to properly "clean up" a closed window?

(Full code: https://github.com/nic547/AvaloniaRepro)

Edit: Does work as expected in 11 preview 8, but not in 11 rc1.1 and 11

@maxkatz6
Copy link
Member

maxkatz6 commented Aug 2, 2023

Likely to be a duplicate of #8240, if automation was used in any way

@flexxxxer
Copy link
Contributor

Reproduced with any automation turned off (like ms windows screen reader). @maxkatz6 i am currently working on this

@timunie
Copy link
Contributor Author

timunie commented Aug 3, 2023

@flexxxxer I assigned you. If you decide to stop working on it, ping me.

github-merge-queue bot pushed a commit that referenced this issue Aug 6, 2023
Fix DataContext not getting GC'd/Finalized. closes #12123
@flexxxxer
Copy link
Contributor

Fixed with #12430

@flexxxxer
Copy link
Contributor

@timunie i think you can close this issue

@flexxxxer flexxxxer removed their assignment Aug 7, 2023
@timunie
Copy link
Contributor Author

timunie commented Aug 7, 2023

@flexxxxer fyi in Fixed Issues, write Fixes #TheIssueNumber. "Fixes" and "Closes" are key words for Github.

@timunie timunie closed this as completed Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants