Although the interface is mainly used to clean up non -hosting resources, it can also be used to clean up the custody resources, thereby providing additional flexibility and control of resource management.
Use IDISPOSABLE to release memory in time IDisposable
objects). This method is very useful when you hope to immediately release memory instead of relying on garbage recychers, which may improve performance. Dispose
List<string>
However, it is important to note that the Dictionary<string, point>
method should be released
resources, which may include the handle, database connection or operating system object. The hosting resources will eventually be recycled by the garbage recyrior, so it is not necessary or ideal to release them to release the Dispose
method.
Release hosting and non -hosting resources Dispose
Rewriting the
Finalize
Dispose(Boolean)
Rewam true
Dispose
Method and call IDisposable.Dispose
Auxiliary method Dispose(true)
, this method handles non -hosting resources and optional custody resources to clean up. When the method is called, it is passed into GC.SuppressFinalize(this)
to indicate that the hosting resources should not be released. Dispose(Boolean)
In order to optimize the resources management, please follow the following best practice: Finalize
false
Consider
UseDispose
rather than rely on the terminal, because the exact time of the terminal is unpredictable. Dispose
The above is the detailed content of Should I Use IDisposable for Managed and Unmanaged Resources?. For more information, please follow other related articles on the PHP Chinese website!