ALERT

[FREE DEMO] Deploy Your Enterprise Cloud in Minutes

Finalize

Definition - What does Finalize mean?

Finalize is an object method that contains the code required to free unmanaged resources and perform cleanup operations prior to garbage collection (GC).

The finalize method is used to clean up resources not managed by .NET. Although the .NET framework is designed to release managed resources by implicitly performing memory management tasks, unmanaged application resources - like file handles and database connections - must be explicitly released.

Techopedia explains Finalize

While finalize is designed to be implicitly called by GC, the dispose method may be explicitly called by user code to free resources.

Finalize is similar to traditional C++ destructors, as each is responsible for freeing object resources. C++ destructors are executed immediately when an object goes out of scope, whereas finalize is called during object cleanup at GC. In C#, finalize cannot be directly called or overridden. If a destructor is declared, it is converted to the finalize method when the program is compiled.

During finalize, memory allocation or calling virtual methods must be avoided. The scope of finalize should be protected so that it is only accessed within the same class or its derived class. Finalize should not reference any other objects. In C#, calling finalize directly on an object other than its base class is an invalid operation. Finalization code should be minimal without any calls capable of blocking the calling thread. As finalize is called by a dedicated thread, its code should not use thread local storage or any technique requiring thread affinity.

Using finalize as a fallback mechanism for releasing unmanaged memory or resources is essential, due to lack of determinism and effects on GC performance.

This definition was written in the context of .NET

Techopedia Deals

Connect with us

Techopedia on Linkedin
Techopedia on Linkedin
Tweat cdn.techopedia.com
"Techopedia" on Twitter


'@Techopedia'
Sign up for Techopedia's Free Newsletter!

Email Newsletter

Join thousands of others with our weekly newsletter

Resources
The 4th Era of IT Infrastructure: Superconverged Systems
The 4th Era of IT Infrastructure: Superconverged Systems:
Learn the benefits and limitations of the 3 generations of IT infrastructure – siloed, converged and hyperconverged – and discover how the 4th...
Approaches and Benefits of Network Virtualization
Approaches and Benefits of Network Virtualization:
Businesses today aspire to achieve a software-defined datacenter (SDDC) to enhance business agility and reduce operational complexity. However, the...
Free E-Book: Public Cloud Guide
Free E-Book: Public Cloud Guide:
This white paper is for leaders of Operations, Engineering, or Infrastructure teams who are creating or executing an IT roadmap.
Free Tool: Virtual Health Monitor
Free Tool: Virtual Health Monitor:
Virtual Health Monitor is a free virtualization monitoring and reporting tool for VMware, Hyper-V, RHEV, and XenServer environments.
Free 30 Day Trial – Turbonomic
Free 30 Day Trial – Turbonomic:
Turbonomic delivers an autonomic platform where virtual and cloud environments self-manage in real-time to assure application performance.