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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:23:41+00:00 2026-05-24T16:23:41+00:00

what happens if i link a method of some object to a delegate, and

  • 0

what happens if i link a method of some object to a delegate, and then dispose of the object?

Like this:

class Hunter
{
    public event Action Shoot;

    public execute()
    {
        Form formBabySeal = new Form();

        Shoot += formBabySeal.Close;

        formBabySeal.Show();
        formBabySeal.Close(); //Dispose Form

        if (Shoot != null)
        {
             Shoot(); //event is null?
        }
    }
}
  • 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-24T16:23:42+00:00Added an answer on May 24, 2026 at 4:23 pm

    formBabySeal is not null just because you dispose it. So, formBabySeal.Close() will be called.

    Your code is equivalent to this when looking at what methods are called:

    Form formBabySeal = new Form();
    
    formBabySeal.Show();
    formBabySeal.Close(); //Dispose Form
    formBabySeal.Close();
    

    This will close the form (first call to Close) and the second call won’t do anything, because the form is already closed.

    However, as Steve points out in the comment section, your code will introduce a memory leak, because Shoot still holds a reference to the Close method of formBabySeal and because of this formBabySeal will be kept alive as long as the instance of the class Hunter is alive.

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

Sidebar

Related Questions

What happens in the memory when a class instantiates the following object? public class
This happens repeatedly and is very annoying. I upload some PHP code to a
I am looking for a method to have a JQuery-like sortable list ( link
I have some mark-up like: <th>Header <a class=uiFilter>Filter</a></th> and some code like: $('.uiGridHeader th').click(theadClick);
There is a link at the bottom. Pretty much what happens, is when the
I have referred to similar questions like this and have done exactly the same
I am trying to open this uri https://some-host/a/meta? (this url is passed to proxi.jsp
I have some destructive action to be performed, so I think it's Rails way
I'm looking at some GXT code for GWT and I ran across this use
I am using the Business Silverlight application. I have incorporated some MVVM into this

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.