Are all the built-in Classes in .net frame work managed?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

are they all garabege collected?

that mean do they all have __gc declared?

and When we should use __gc to point to a varaible ? i am new to the .net world, and i find it really similar to Java.
 
Hi,

All CTS(Common Type System) datatypes are managed, however a number of them
do own unmanaged resources. In the case where a data type owns unmanaged
resources, these resource are typically released when the type instance is
finalized unless the programmer has explicitly invoked the Dispose method of
the instance. As a rule, types that own unmanaged resources implement
IDisposable interface in there hierarchy.

In many ways the .NET environment is similar to the Java environment however
there are also many phylosophical differences that make these environments
very different from each other. So in my opinion, on the surface they share
many cominalities, while they differ in many details.

Hope this helps
--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor


RetoraiSeaSer said:
are they all garabege collected?

that mean do they all have __gc declared?

and When we should use __gc to point to a varaible ? i am new to the .net
world, and i find it really similar to Java.
 
All classes written in .NET are managed, they get garbage collected.
However, a class may contain resources that are not managed, e.g. file
handles, database connection.
The common practice is to implement the IDispose interface (class gets a
Dispose method), this will allow the programmer to explicitly release
unmanaged resources.
In addition to IDispose, a class may implement a finalizer, this is called
when the instance is reclaimed by the garbage collector, it may just call
the Dispose method, usefull incase the programmer forgets to call Dispose.
Finalizers should only be used with care as they have a performance impact
on the garbage collector, do not implement it if your class only contains
managed code.
One scenario where finalizers make sence is if you are wrapping unmanaged
C++ code, if you only rely on Dispose and the programmer forgets to call it,
you get a memory leak.

__gc is the Managed C++ way of marking a class as managed reference type.

..NET uses references, not pointers. They are similar but a pointer is
normally meant to indicate a specific memorylocation that doesn't change
during execution. A reference points to an object, the objects location in
memory can be changed by the garbage collector at any time.

In the current Managed C++ implementation, the syntax for pointers and
references look the same, the type of class determines if pointer or
reference is used. Visual Studio 2005 and .NET 2.0 will have a seperate
syntax for pointers and references.

Chris

RetoraiSeaSer said:
are they all garabege collected?

that mean do they all have __gc declared?

and When we should use __gc to point to a varaible ? i am new to the .net
world, and i find it really similar to Java.
 
Back
Top