Developer community
0 votes
20 views
asked by Guru (24.6k points) 30 54 84 | 20 views

2 Answers

0 votes

 

CLR uses the Dispose and Finalize methods to perform garbage collection of run-time objects of .NET applications.
 
The Finalize method is called automatically by the runtime. CLR has a garbage collector (GC), which periodically checks for objects in heap that are no longer referenced by any object or program. It calls the Finalize method to free the memory used by such objects. The Dispose method is called by the programmer. Dispose is another method to release the memory used by an object. The Dispose method needs to be explicitly called in code to dereference an object from the heap. The Dispose method can be invoked only by the classes that implement the IDisposable interface.
 
 
answered by Expert (13.2k points) 27 43 61
0 votes
Dispose() is called by the user of an object to indicate that he is finished with it, enabling that object to release any unmanaged resources it holds. Finalize() is called by the run-time to allow an object which has not had Dispose() called on it to do the same. However, Dispose() operates determinalistically, whereas there is no guarantee that Finalize() will be called immediately when an object goes out of scope - or indeed at all, if the program ends before that object is GCed - and as such Dispose() is generally preferred.
answered by Guru (24.6k points) 30 54 84

Related questions

0 votes
0 answers
asked by rock Expert (15k points) 15 23 31 | 139 views
0 votes
1 answer
0 votes
1 answer
asked by john Guru (27.1k points) 35 52 103 | 79 views
0 votes
1 answer
asked by sara Guru (24.6k points) 30 54 84 | 40 views
0 votes
1 answer
asked by john Guru (27.1k points) 35 52 103 | 70 views
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

Categories


C Books Guide and List
C++ Books Guide and List
Best Java Books

3.8k questions

4k answers

117 comments

10.7k users

3,754 questions
4,046 answers
117 comments
10,709 users