TCS Placement: Sample Questions 272 - 272 of 502

Get unlimited access to the best preparation resource for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 272

Edit

Describe in Detail

Essay▾

State the differences between the Dispose () and Finalize () .

Explanation

CLR uses the Dispose and Finalize methods to perform garbage collection of run-time objects of . NET applications.

Difference between the Dispose () and Finalize ()
Finalize ()Dispose ()
The Finalize method is called automatically by the runtime.The Dispose method is called by the programmer.
CLR has a garbage collector (GC) , which periodically checks for objects in heap that are no longer referenced by any object or program.Dispose is another method to release the memory used by an object. The Dispose method is explicitly called in code to dereference an object from the heap.
It calls the Finalize method to free the memory used by such objects.Dispose method can be invoked only by the classes that implement the IDisposable interface.
Can be used to free unmanaged resources like files, database connections etc. held by an object before that object is destroyed.Used to free unmanaged resources like files, database connections etc. at any time.
Implemented with the help of destructor in C ++ & C#.Implemented by IDisposable interface Dispose () method.

Developed by: