C# GC.SuppressFinalize: When and Why to Call It
Learn when and why to call GC.SuppressFinalize in C#, how it interacts with finalizers and IDisposable, and common pitfalls.

The GC.SuppressFinalize method appears in almost every IDisposable implementation, yet its purpose is often misunderstood. Calling it incorrectly can lead to resource leaks or subtle bugs. This article explains what it does, why the standard dispose pattern includes it, and when you should—or should not—call it.
The Problem Finalizers Are Designed to Solve
A finalizer is a method that the garbage collector runs before reclaiming an object's memory. It is declared like a destructor in C#:
public class ResourceHolder
{
~ResourceHolder()
{
// Clean up unmanaged resources here
}
}Finalizers exist to handle unmanaged resources—file handles, network sockets, database connections—that the runtime does not manage automatically. If an object holds such a resource and the developer forgets to release it explicitly, the finalizer provides a safety net.
But finalization is not free. Objects with finalizers are placed on the finalization queue when they are created. When the garbage collector determines they are unreachable, it does not reclaim their memory immediately. Instead, it moves them to the f-reachable queue and a dedicated finalizer thread runs their finalizers. Only after that does the memory become eligible for collection. This means finalizable objects survive at least one extra garbage collection, which increases memory pressure and slows down the entire process.
What GC.SuppressFinalize Does
GC.SuppressFinalize tells the garbage collector that an object's finalizer no longer needs to be run. The method takes the object as a parameter and removes it from the finalization queue. Once called, the finalizer will not execute, even if the object is later collected.
The typical call looks like this:
public void Dispose()
{
GC.SuppressFinalize(this);
}Why would you want to suppress finalization? Because if your Dispose method already performs all the cleanup that the finalizer would have done, there is no reason to run the finalizer later. Suppressing it avoids the extra cost of finalization and prevents the object from lingering in memory for an additional collection cycle.
The Standard Dispose Pattern
The canonical dispose pattern combines a finalizer and Dispose so that cleanup happens whether the developer calls Dispose explicitly or relies on the finalizer as a fallback. The pattern looks like this:
public class ResourceHolder : IDisposable
{
private bool _disposed;
private IntPtr _handle; // unmanaged resource
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (_disposed) return;
if (disposing)
{
// Release managed resources
}
// Release unmanaged resources
CloseHandle(_handle);
_disposed = true;
}
~ResourceHolder()
{
Dispose(false);
}
}The Dispose(bool) overload is the core cleanup logic. When called with true, it releases both managed and unmanaged resources. When called with false—which happens only from the finalizer—it releases only unmanaged resources, because managed resources may already have been collected.
The key point is that GC.SuppressFinalize(this) is called at the end of the public Dispose method. This ensures that if the developer explicitly disposes the object, the finalizer will not run later. If the developer forgets to call Dispose, the finalizer will eventually run and clean up unmanaged resources, preventing a leak.
When to Call SuppressFinalize
You should call GC.SuppressFinalize in the public Dispose method of a class that has a finalizer and whose cleanup fully handles what the finalizer would otherwise do. In the canonical pattern, that call appears only in the public Dispose method; derived Dispose(bool) overrides do not call it again.
There are also cases where you should not call it:
- If cleanup is incomplete. If
Disposereleases only part of a resource and relies on the finalizer to finish the job, suppressing finalization will leak the rest. This is rare in a correctly implemented pattern. - If cleanup could fail. Some cleanup operations can throw. If
Disposethrows before releasing a resource, the finalizer should still run as a fallback. CallGC.SuppressFinalizeonly after all cleanup has completed successfully. - If there is no finalizer to suppress. If no type in the object's hierarchy declares a finalizer,
GC.SuppressFinalizehas no effect. It is harmless, but it is usually redundant.
Performance and Finalization Cost
The most direct performance impact of GC.SuppressFinalize is that it removes the object from the finalization queue. This has two benefits:
- The object is reclaimed in a single garbage collection. Without suppression, a finalizable object survives at least two collections: one to move it to the f-reachable queue and another to reclaim its memory after the finalizer runs.
- The finalizer thread is not invoked. Finalizer threads run at a lower priority and can introduce latency spikes. Suppressing finalization avoids that overhead entirely.
For objects that are frequently created and disposed, such as stream wrappers or database connections, the difference can be measurable. The exact impact depends on how often the object is collected and how busy the finalizer thread is. But in general, calling SuppressFinalize in Dispose is a low-cost way to reduce GC pressure.
It is worth noting that GC.SuppressFinalize itself is a very fast operation—it simply marks the object as not needing finalization. The cost is negligible compared to the finalization it prevents.
Common Mistakes and Edge Cases
One common mistake is calling SuppressFinalize too early. If you call it before all resources are released, the finalizer will never run, and you risk leaking unmanaged resources. Always place the call after the cleanup logic has completed successfully.
Another common mistake is adding an extra GC.SuppressFinalize call in a derived class when the public Dispose method is inherited. In the pattern used above, ResourceHolder.Dispose is non-virtual and calls GC.SuppressFinalize(this). Because this is the actual runtime type, this call prevents the finalizer chain for the derived instance too. A derived class that overrides Dispose(bool) does not need to add another suppression call.
Here is an example of a derived class:
public class DerivedResourceHolder : ResourceHolder
{
private bool _disposed;
protected override void Dispose(bool disposing)
{
if (_disposed) return;
if (disposing)
{
// Release derived-class managed resources
}
// Release derived-class unmanaged resources
_disposed = true;
base.Dispose(disposing);
}
~DerivedResourceHolder()
{
Dispose(false);
}
}Notice that the derived class has its own finalizer and its own _disposed flag. When Dispose is called on a derived instance, the inherited public Dispose invokes the virtual Dispose(bool), so derived cleanup runs, then base cleanup runs. After Dispose(bool) returns, the inherited public Dispose calls GC.SuppressFinalize(this). Since this is the derived instance, finalization of the derived object is suppressed. That is correct.
If a derived class does not define its own finalizer, the inherited public Dispose call still suppresses finalization for the derived object. The rule is not to add a suppression call for every finalizer; it is to call GC.SuppressFinalize once from the public Dispose method that completes all cleanup.
Interaction with Inheritance and Derived Classes
When a class hierarchy involves finalizers, the interaction between Dispose and SuppressFinalize becomes more delicate. The base class's Dispose method calls GC.SuppressFinalize(this), and because this is the actual runtime type, it prevents the finalizer chain for the most derived class. That finalizer, if present, would have called Dispose(false) on the derived class, which would have called the base cleanup as well. By suppressing it, you are telling the runtime that the explicit Dispose(true) path already handled everything.
This works only if every class in the hierarchy correctly implements the dispose pattern. If a derived class introduces a new unmanaged resource but forgets to override Dispose or add a finalizer, that resource may leak when the object is not explicitly disposed. The base class cannot know about resources in derived classes.
A practical approach for complex hierarchies is to mark the Dispose(bool) method as protected virtual and ensure each level calls the base implementation. The public Dispose method should be non-virtual and should call GC.SuppressFinalize once. This keeps the suppression logic in one place while allowing each class to add its own cleanup.
Another edge case is when an object is resurrected in its finalizer. If a finalizer assigns this to a static or instance field, the object becomes reachable again and will not be collected. If you have already called SuppressFinalize, the finalizer will not run, so resurrection cannot happen. This is usually desirable, but it means you cannot rely on finalization for any last-minute state restoration after Dispose has been called.
Finally, consider the case where Dispose is called multiple times. The standard pattern uses a _disposed flag to ensure cleanup runs only once. GC.SuppressFinalize is idempotent, so calling it multiple times is harmless. But the flag prevents the cleanup logic from running more than once, which is important for correctness.
In summary, GC.SuppressFinalize is a simple method with a clear purpose: it tells the garbage collector that the object's finalizer is no longer needed because cleanup has already been performed. Use it in a Dispose implementation that fully handles resource release, and make sure it is called after all cleanup has succeeded. Understanding how it interacts with finalizers and inheritance will help you avoid the subtle bugs that can arise from improper use.
Try matching browser tools
All toolsSmall utilities that fit C# work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related C# guides
All C# guidesC# Dispose vs Destructor: Key Differences Explained
c# dispose vs destructor: Understand the difference between Dispose and destructors in C#, when each runs, and how to manage unmanaged resources correctly.
C# Variable Declaration: Syntax and Practical Usage
Learn how to declare variables in C# with explicit types, var, and nullable annotations, and understand how defaults, scope, and readability affect your choices.
C# Primary Constructors for Classes: Syntax and Usage
Learn how to use C# primary constructors for classes: syntax, initialization, dependency injection, and limitations with practical examples.
C# IComparer: Custom Sorting with IComparer<T>
Learn how to implement IComparer<T> in C# to define custom sort order for arrays and lists, handle nulls, and avoid common performance pitfalls.
More in C#
All C# guidesThe guides filed next to this one in C#, in library order.