Sasi Rekha
Dispose() in Destructor in C#?
By Sasi Rekha in .NET on Mar 09 2018
  • Asif Khan
    Apr, 2018 2

    Dispose() method is used for explicit cleanup of object from memory.The dispose pattern is used only for objects that access unmanaged resources, such as file and pipe handles, registry handles, wait handles, or pointers to blocks of unmanaged memory.

    • 2
  • Ishoo Anyal
    Sep, 2019 27

    Dispose methode is used to clear unmanaged objects and resources. Now what are unmanaged resources in .NetFramework? Ans. is none but .net uses resources out of .Net framework as well like File handeling, SQlConnection which needs to be disposed.
    Example
    `using(SqlConnection conn = new SqlConnection(connectionString)){

    }`

    then dispose method is alled after this using block is completed

    If you want to call dispose for you class then you need to implemet IDisposable interface and do whatever this interface asks you to do

    • 0
  • Deepak Verma
    May, 2018 21

    .NET Framework provides Dispose() method for releasing unmanaged resources like files, database connections, COM etc. It is called by user code and the class which is implementing dispose method must have to implement the IDisposable interface. Their is no performance costs associated with Dispose method.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS