Monday, June 16, 2008

Managing Scarce Resources

Managing Scarce Resources
2.1 Unmanaged Resources
As we have already mentioned, unmanaged resources are resources that cannot be released by the GC directly. Examples of unmanaged resources include file handles, database connection handles, message queue handles, and native memory allocated using Marshal.AllocHGlobal.
Releasing unmanaged resources requires an explicit call to a custom API, something along the lines of closing a “handle”.

2.2 Managed Resources
Managed resources are resources that can be released by the GC directly. Examples of managed resources include String, ArrayList, and TimeSpan. Code acquiring managed resources does need to be concerned with releasing them.
Instantiating and calling methods of managed types does not always allocate only managed resources, as it may seem. It may indirectly allocate unmanaged resources.

No comments: