A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/unmanaged below:

Cleaning up unmanaged resources - .NET

For a majority of the objects that your app creates, you can rely on the .NET garbage collector to handle memory management. However, when you create objects that include unmanaged resources, you must explicitly release those resources when you finish using them. The most common types of unmanaged resources are objects that wrap operating system resources, such as files, windows, network connections, or database connections. Although the garbage collector is able to track the lifetime of an object that encapsulates an unmanaged resource, it doesn't know how to release and clean up the unmanaged resource.

If your types use unmanaged resources, you should do the following:

Consumers of your type can then call your IDisposable.Dispose implementation directly to free memory used by unmanaged resources. When you properly implement a Dispose method, either your safe handle's Finalize method or your own override of the Object.Finalize method becomes a safeguard to clean up resources in the event that the Dispose method is not called.

In this section

Implementing a Dispose method describes how to implement the dispose pattern for releasing unmanaged resources.

Using objects that implement IDisposable describes how consumers of a type ensure that its Dispose implementation is called. We strongly recommend using the C# using (or the Visual Basic Using) statement to do this.

Reference Type / Member Description System.IDisposable Defines the Dispose method for releasing unmanaged resources. Object.Finalize Provides for object finalization if unmanaged resources are not released by the Dispose method. GC.SuppressFinalize Suppresses finalization. This method is customarily called from a Dispose method to prevent a finalizer from executing.

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4