Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6650071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:50:58+00:00 2026-05-26T00:50:58+00:00

If parent window A passes a reference to itself to child window B (via

  • 0

If parent window A passes a reference to itself to child window B (via constructor) so that B can set its Owner property to A, does that mean child window B won’t be garbage collected because parent window A stays alive for the duration of the application?

If this is the case, what is the best approach for creating clean parent/child relationships between WPF windows? Is there a concept of weak references for this type of relationship?

UPDATE: Brain FAIL. Okay, I shouldn’t have asked this question so late in the afternoon. I was over-complicating the problem. My brain reversed the logic of the GC and was thinking the child couldn’t collect because it referenced something else which is totally false. Thanks to all who answered anyway.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:50:59+00:00Added an answer on May 26, 2026 at 12:50 am

    I created the Windows you mention, and added some code:

    // XAML in Window A
    
    <StackPanel>
        <Button Click="Button_Click">Show Window</Button>
        <Button Click="Button_Click_1">Garbage Collect</Button>
    </StackPanel>
    
    // Code in Window A
     private void Button_Click(object sender, RoutedEventArgs e)
            {
                WindowB windowB = new WindowB(this);
                windowB.Show();
            }
    
            private void Button_Click_1(object sender, RoutedEventArgs e)
            {
                GC.Collect();
            }
    
        // Code in WindowB
        public WindowB(WindowA windowA)
        {
            this.Owner = windowA;
            InitializeComponent();
        }
    
        ~WindowB()
        {
            Console.WriteLine("Gone up in a puff of smoke");
        }
    

    Once B had been closed and the second button pressed, the destructor ran. Hopefully this answers the question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to close parent window from child window using javascript, but its
Is it possible to make that when child window is opened, parent window is
In my child window I have $('#opfile').addOption(someval,sometext); Problem is #opfile is an a parent
For my web application I need to close the child window whenever the parent
i have a parent window and a child window. in javascript, i want a
How to pass value from parent to child window field. I use window.open(www.google.com); after
How can a browser window know if it is a parent window or a
How can I call the parent-window jquery function with variable from popup window javascript?
I am trying to set the value to the hidden field in parent window
I am reading from MSDN this: A child window has only one parent window,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.