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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:34:53+00:00 2026-05-14T14:34:53+00:00

Since C# uses Garbage Collection. When is it necessary to use .Dispose to free

  • 0

Since C# uses Garbage Collection. When is it necessary to use .Dispose to free the memory?

I realize there are a few situations so I’ll try to list the ones I can think of.

  1. If I close a Form that contains GUI type object, are those objects dereferenced and therefore will be collected?
  2. If I create a local object using new should I .Dispose of it before the method exits or just let the GC take care of it? What is good practice in this case?
  3. Are there any times in which forcing a GC is understandable?
  4. Are events collected by the GC when it’s object is collected?
  • 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-14T14:34:54+00:00Added an answer on May 14, 2026 at 2:34 pm

    In theory, if you have properly defined componentry, it should never be required to call Dispose() on your objects, as the finalizer should eventually take care of it.

    That being said, any time you’re using an object that implements IDisposable, it’s a good practice to call Dispose() on the object as soon as you are through working with it.

    For some of your specific points:

    1) If you know you’re “done” with the Form, you can call Dispose() on it. This will force a cleanup at that point in time of the unmanaged resources associated with the form.

    2) In this case: if your object is just used in that method, use “using” instead:

    using (MyObject myObject = new MyObject())
    {
       // use your object
    } // It'll be disposed of here for you
    

    3) There are rare reasons to do this, but in general, no.

    4) Events are a delegate – the memory associated with the delegate will be collected after the delegate itself becomes unrooted, which typically happens when the objects in question are unrooted.

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

Sidebar

Related Questions

Since enumeration uses integers, what other structure can I use to give me enum-like
When we can get good speed with OpenGL since it uses texture memory and
I know there is a WeakHashMap in java.util , but since it uses WeakReference
Since PHP uses data from ICU in the intl extension, are there ways to
We are currently using SharpZipLib but since it uses the GPL we need to
IIS does not work when I start applications like Skype since it also uses
Since Hex (base 16) uses 0-9A-F, and (I'm assuming here) Base 17 uses 0-9A-G
I know SysCache uses ASP caching under the hood, but since I'm not aware
I have a spring application that uses an embedded Jetty instance. Since I am
The docs for Camelot say that it uses Elixir models. Since SQLAlchemy has included

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.