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.