Esteban
Esteban

Reputation: 3127

Why use GC.SuppressFinalize() when there is no Finalizer?

As the question states, I just wanted to know, because I've been asked and I don't have a clue, is there any reason for this whatsoever?

Upvotes: 3

Views: 1550

Answers (2)

Henk Holterman
Henk Holterman

Reputation: 273711

When a class does not define a Finalizer (destructor), a call to SuppressFinalize() on an instance of that class has no effect.

When you see it, it usually is a left-over of the full Disposable implementation. Just remove it or ignore it.

Upvotes: 7

Roman Zavalov
Roman Zavalov

Reputation: 585

The reason might be to prevent potential error if someone adds a finalizer later on and forgets to add GC.SuppressFinalize().

Upvotes: 3

Related Questions