1

There are some classes such as DataTable who already called SuppressFinalize in its constructor and so there is no point to call dispose/use using on it. (because dispose is for releasing earlier but there is nothing to release)

So, I want to know a list of such classes or a way to find a list of such classes by reflection?

akjoshi
  • 15,374
  • 13
  • 103
  • 121
ill mg
  • 331
  • 4
  • 8
  • 1
    If Gideon's answer is useful to you and helped answer your question, you should mark it as accepted. To do that, hit the check mark to the left of the answer. If it wasn't useful to you, you should ask for more clarification, or add more details to your question. I'd recommend you do this with all your questions that don't have an accepted answer. – Merlyn Morgan-Graham Nov 04 '11 at 06:40

1 Answers1

6

Your question makes an invalid assumption. Calling SuppressFinalize has no bearing on the usefulness of Dispose. The Dispose method will still do whatever is written in it when you call it, either explicitly or via a using block.

Typically, Dispose will call SupressFinalize, but this is because Dispose will execute the code that would have run from the finalizer when you follow the typical Dispose pattern. Since the code has already been run, there is no need for finalization, which is a relatively expensive operation, thus Dispose will call SupressFinalize.

Gideon Engelberth
  • 6,095
  • 1
  • 21
  • 22
  • But on both stackoverflow and the internet there are numerous answers saying practically there is no need to call dispose for datatable even though it got IDisposable from its base class. Should it be called or not? Or should I actually ask what class with IDisposable actually does not need its dispose called instead? – ill mg Oct 25 '11 at 04:39
  • 2
    @illmg That would be the better question, but still may only be useful as trivia. In general, if it implements IDisposable, I would dispose it rather than trying to dig into the implementation details to find out if I really need to. This can also prevent bugs where you switch to a similar class or interface implementation that does need disposed, but forget to add the call. – Gideon Engelberth Oct 25 '11 at 04:46