Click here to Skip to main content
15,998,056 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Let me know what are the "Unmanaged resources" in manged code whose memory management is not done by the garbage collector
Posted

1 solution

Quote:
Managed resources basically mean anything managed by the CLR (example: any of your managed objects). Unmanaged resources typically mean native resources that are created and lifetime managed outside the CLR (example GDI handles or say sockets).


The term "unmanaged resource" is usually used to describe something not directly under the control of the garbage collector. For example, if you open a connection to a database server this will use resources on the server (for maintaining the connection) and possibly other non-.net resources on the client machine, if the provider isn't written entirely in managed code.

This is why, for something like a database connection, it's recommended you write your code thusly:
C#
using (var connection = new SqlConnection("connection_string_here"))
{
    // Code to use connection here
}

As this ensures that .Dispose() is called on the connection object, ensuring that any unmanaged resources are cleaned up.
Refer:
http://msdn.microsoft.com/en-us/library/498928w2(v=vs.110).aspx[^]
managed and unmanaged resources[^]
 
Share this answer
 
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900