Managed resources - a definition?

  • Thread starter Thread starter Paul [Paradise Solutions]
  • Start date Start date
P

Paul [Paradise Solutions]

Hi all

Working towards 'properly' coding my apps, so I thought I'd look into
the whole imlimenting Dispose() palava.
Via some google postings I found some MS documentation, but I'm a little
unclear on the meaning of the phrase 'managed resources'. I was
wondering if someone could confirm a 'plain english' definition.
Would I be right in assuming if you have some objects and some plain
variables (say a SQL connection, a SQL command and a few strings) would
the SQL objects be considered as the managed resources and the strings
unmanaged?


Many thanks


Paul
 
Managed resources are essentially anything which exists within memory over
which the .NETCF runtime has control of and can be garbage collected.
Unmanaged resources are those created outside of the .NETCF environment and
include items such as file/device handles, and unmanaged memory blocks
allocated outside of your application either by api functions such as
LocalAlloc or by the system itself.
Any managed resources (and this includes strings created in .NETCF code) can
be reclaimed by the garbage collector when they are out of scope and the
system requires more free memory. Unmanaged resources must be manually freed
to avoid memory leaks.

In the scenario you describe any strings or other variables you create are
managed. The Sql Classes will internally use some unmanaged resources to
interop with the SqlServerCe database, however the freeing of these is
handled within the SqlServerCe classes when you Close and Dispose these
objects.

Peter
 
Thanks for the info there - I think I acually learnt something...



Many thanks

Paul
 
Back
Top