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

  • SEARCH
  • Home
  • 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 618119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:30:37+00:00 2026-05-13T18:30:37+00:00

I create a window like this: if (someCondition) { MyWindow wnd = new MyWindow();

  • 0

I create a window like this:

if (someCondition)   
{  
   MyWindow wnd = new MyWindow();  
   wnd.Owner = this;  
   wnd.ShowDialog();  
}  

I want MyWindow’s destructor to be called at the closing curly bracket, but it doesn’t. Do I need to call something like delete/destroy for MyWindow’s destructor to be called?

  • 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-13T18:30:37+00:00Added an answer on May 13, 2026 at 6:30 pm

    The “destructor” or finalizer as it is called in C# is called whenever the Garbage Collector feels like. You can trigger the Garbage Collector manually using System.GC.Collect(), but you probably don’t want to do this. If your talking about Dispose() on the other hand you can make this being called by creating the window in a “using” clause:

    using (var wnd = new MyWindow())
    {
        wnd.Owner = this;  
        wnd.ShowDialog(); 
    }
    

    This would make wnd.Dispose() be called when the using clause is done, and would basically be the same as writing:

    var wnd = new MyWindow(); 
    wnd.Owner = this;  
    wnd.ShowDialog();     
    wnd.Dispose(); 
    

    About the usage of the IDisposable interface this question might be helpful – and several more on StackOverflow.

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

Sidebar

Related Questions

i want to create a Window in an ControlLibrary called MyWindow so that i
When you create a new browser window, you pass it a name like this:
Can I create a window without this topbar? : I want a window like
How do I create a window which looks like this in Java: I want
I want to a create dialog box like window before displaying the console window.
I want to create a Window like when a context menu pops up or
I'm creating a modal dialog like this window.NewPageModalView = Backbone.View.extend({ template: _.template($('#view-template-new-page-dialog').html()), el: $('div#main'),
I want to be able to create window like boxes by clicking on an
I'd like to create a WPF control for a window tab, and I want
all i want to create the header file for database like this. it contains

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.