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 6563041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:46:55+00:00 2026-05-25T13:46:55+00:00

This is another question about well disposing objects from .NET. After having read a

  • 0

This is another question about well disposing objects from .NET. After having read a lot of different arcticles about dispose best practices (and people opinions), I was not able to get an answer for that one. I have 2 forms, Form1 and Form2.

Form1

void ShowFormButton_Click(object sender, eventargs e)
{
    Form2 form = new Form2();
    form.TextChanged += new eventhandler(form_TextChanged);
    form.Show(this);
}

Form2

void CloseFormButton_Click(object sender, eventargs e)
{
    Close();
}

When calling Close() in Form2, the Form2 should have is dispose() method call because it was opened by calling is Show() method but because Form1 has registered for the TextChanged event or Form2, will this keep Form2 from being disposed or make the process of disposing by the GC less efficient?

Thanks in advance

  • 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-25T13:46:56+00:00Added an answer on May 25, 2026 at 1:46 pm
    Form2 form = new Form2(); 
    form.TextChanged += new eventhandler(form_TextChanged);
    

    This means, that Form2 instance has reference to Form1 form_TextChanged method. When Form2 is closed, this doesn’t prevent it to be collected, so in this case unsubscribing is not obligatory.

    Let’s say that Form2 subscribes to Form1 event. In this case, when Form2 is closed, Form1 still has active reference to Form2, and Form2 cannot be collected, creating memory leak.

    So, the answer depends on subscription direction and event source/subscriber life time. In any case, if something is not clear, it is better to unregister events.

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

Sidebar

Related Questions

Ok another WPF question, well I guess this is just general .NET. I have
this kind of follows on from another question of mine. Basically, once I have
I have a simple question about .net delegates. Say I have something like this:
This is a spin off from another question I posted a few days ago
From all the articles I've read so far about Mochiweb, I've heard this over
I saw this tip in another question and was wondering if someone could explain
In a comment on this answer to another question , someone said that they
I'll try to explain this better on another question. This is the query that
This question is based on another question of mine (thankfully answered). So if in
This question is related to another question which I asked yesterday! List all links

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.