Difference between destructor, dispose and finalize method

PHOTO EMBED

Tue Jun 28 2022 14:41:06 GMT+0000 (Coordinated Universal Time)

Saved by @Marcos_ #cs

class Car
{
    ~Car()  // destructor
    {
        // cleanup statements...
    }
}

protected override void Finalize()
{
    try
    {
        // Cleanup statements...
    }
    finally
    {
        base.Finalize();
    }
}

content_copyCOPY

As per my research and understandings, having a Destructor method within my class will tell the garbage collector to perform the garbage collection in the way mentioned in the destructor method which cannot be called explicitly on the instances of the class. The Dispose method is meant to provide the user to control the garbage collection. The Finalize method frees the resources used by the class, but not the object itself.

https://stackoverflow.com/questions/13988334/difference-between-destructor-dispose-and-finalize-method