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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:20:53+00:00 2026-05-31T17:20:53+00:00

Garbage Collection can become a time consuming process. In this regard, the GC tends

  • 0

Garbage Collection can become a time consuming process. In this regard, the GC tends to work only when it has to. If an object has been disposed, to help save time and aid the GC, should the GC’s finalizer be suppressed?

using(var sO = new someObject())
{
 //work with object
}

public class someObject : IDisposable
{
  internal Stream someResource;
  internal Context someContext;

  public void Dispose()
  {
   someContext.Dispose();
   someResource.Dispose();
   //A: does suppressing the GC finalizer here save time for the GC?
   //B: can this cause memory leaks?
   //GC.SuppressFinalize(this);
  }
}
  • 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-31T17:20:54+00:00Added an answer on May 31, 2026 at 5:20 pm

    To clear up some confusion:

    • You only need a finalizer if you need to clean up unmanaged resources in some special way.

    • If you have no unmanaged resources, then you don’t need a finalizer.

    • If you have a finalizer, then you should definitely implement IDisposable.

    • If you have a finalizer, then you should call GC.SuppressFinalize in Dispose, because the finalizer doesn’t need to be called if you’ve already cleaned up after yourself.

    • You only need to call GC.SuppressFinalize if you have a finalizer. If you don’t, you probably still want to call it anyway as a defensive measure.

    does suppressing the GC finalizer here save time for the GC?

    If there are unmanaged resources and your object has a finalizer, then yes; your object might live a long time on the finalization queue if you don’t suppress this. The resources you dispose of may also take a long time to finalize (closing an expensive I/O channel, for example).

    If you don’t have a finalizer, you’re saying that you don’t have anything unmanaged to clean up. You should still call SuppressFinalize anyway as a defensive measure.

    From the FxCop rules:

    “Failure to suppress finalization degrades performance and provides no benefits.”


    For your other question,

    can this cause memory leaks?

    In this example, yes, if any of the resources are unmanaged. If your object is terminated in some unusual way before it has a chance to invoke Dispose, unmanaged resources won’t be properly freed. Consider what happens if someResource is unmanaged and throws an exception while you’re using a someObject instance, for example.

    If your object holds onto unmanaged resources and you need to guarantee those resources are cleaned up, you need a finalizer too (which would be named ~someObject in your case).

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

Sidebar

Related Questions

I'm interested in how garbage collection works. I've read up on how some work
This article says If an object has a finalizer, it is not immediately removed
Possible Duplicate: Forcing Garbage Collection in Java? Can I Force Garbage Collection in Java
Is there a way to trigger a garbage collection in a .NET process from
My program has a trouble: When GC perform garbage collection,my program always crashes at
Garbage collection in .NET leads many to believe that lightweight objects can be treated
I have been reading about garbage collection and came to know the term Island
Is a running thread eligable for garbage collection if the thread object is reasigned?
Is a running thread eligable for garbage collection if the thread object is reasigned?
Possible Duplicate: Can I run a .NET garbage collection from WinDbg? I'm debugging a

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.