Gautam Kumar
What is the difference between Finalize() and Dispose() methods?
By Gautam Kumar in C# on Nov 19 2013
  • Dinesh Kumar Sharma
    Feb, 2017 28

    Dispose It belongs to IDisposable interface. and internal called by user code.Finalize It belongs to Object class. and It's implemented with the help of destructor in C#

    • 3
  • Gautam Kumar
    Nov, 2013 19

    Dispose() is called when we want for an object to release any unmanaged resources with them. On the other hand Finalize() is used for the same purpose but it doesn't assure the garbage collection of an object.

    • 1
  • Arun Kumar Tiwari
    Jan, 2020 30

    The main difference between dispose() and finalize() is that the method dispose() has to be explicitly invoked by the user whereas, the method finalize() is invoked by the garbage collector, just before the object is destroyed.

    • 0
  • Bhushan Babras
    Nov, 2017 9

    .NET Framework provides two methods Finalize and Dispose for releasing unmanaged resources like files, database connections, COM etc. - It is always recommended to use Dispose method to clean unmanaged resources. You should not implement the Finalize method until it is extremely necessary.- At runtime C#, C++ destructors are automatically Converted to Finalize method. But in VB.NET you need to override Finalize method, since it does not support destructor.- You should not implement a Finalize method for managed objects, because the garbage collector cleans up managed resources automatically.- A Dispose method should call the GC.SuppressFinalize() method for the object of a class which has destructor because it has already done the work to clean up the object, then it is not necessary for the garbage collector to call the object's Finalize method.

    • 0
  • Rajesh Singh
    Apr, 2016 23

    You can find differences here. http://dotnetmagics.com/difference-between-finalize-and-dispose/

    • 0
  • Rahul Prajapat
    Jun, 2015 1

    Finalize is used internally by garbage collector Used to free unmanaged resources like files, database connections, COM etc. held by an object before that object is destroyed. but Dispose() is used by used externally .........

    • 0
  • Pankaj  Kumar Choudhary
    Jun, 2015 1

    Finalize is used internally by garbage collector Used to free unmanaged resources like files, database connections, COM etc. held by an object before that object is destroyed. but Dispose() is used by used externally

    • 0
  • Krishna Mohan
    May, 2014 16

    Finalize:Used to free unmanaged resources like files, database connections, COM etc. held by an object before that object is destroyed.Internally, it is called by Garbage Collector and cannot be called by user code.It belongs to Object class.Implement it when you have unmanaged resources in your code, and want to make sure that these resources are freed when the Garbage collection happens.There is performance costs associated with Finalize methodDispose:It is used to free unmanaged resources like files, database connections, COM etc. at any time.Explicitly, it is called by user code and the class implementing dispose method must implement IDisposable interface.It belongs to IDisposable interface.Implement this when you are writing a custom class that will be used by other users.There is no performance costs associated with Dispose method.For similar kind of c# interview questions you can refer this link c# interview questions

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS