Why do some people use the Finalize method over the Dispose method?
In what situations would you use the Finalize method over the Dispose method and vice versa?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Others have already covered the difference between
DisposeandFinalize(btw theFinalizemethod is still called a destructor in the language specification), so I’ll just add a little about the scenarios where theFinalizemethod comes in handy.Some types encapsulate disposable resources in a manner where it is easy to use and dispose of them in a single action. The general usage is often like this: open, read or write, close (Dispose). It fits very well with the
usingconstruct.Others are a bit more difficult.
WaitEventHandlesfor instances are not used like this as they are used to signal from one thread to another. The question then becomes who should callDisposeon these? As a safeguard types like these implement aFinalizemethod, which makes sure resources are disposed when the instance is no longer referenced by the application.