NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

__gc

Declares a garbage-collected object.

__gc class-specifier
__gc struct-specifier
__gc interface-specifier

Remarks

A garbage-collected class is a C++ language extension that simplifies NGWS programming by providing features such as interoperability and garbage collection.

Garbage collection is implemented by the NGWS runtime and is a high-performance, asynchronous, compacting algorithm that provides precise tracking of all pointers into the managed heap at runtime. As a result of this garbage collection algorithm, any operations that might hide addresses from the NGWS garbage collector or manipulate them in unsafe ways are disallowed.

Note   The __gc keyword can also be applied to array and pointer types.

For more information on the rules for managed objects, see Managed Classes and Managed Arrays.

For more information on creating and using managed object types, see Writing Managed Programs.

Example

In the following example, a managed class (X) is declared with a public data member:

#using <mscorlib.dll>
#using namespace System;

__gc class X
{
public:
   int i;
   int ReturnInt() { return 5; }
};

void main()
{
   X* px;                    // declares a managed pointer of type X
   px = new X;               // creates a managed object of type X
   px->i = 4;                // modifies X::i through px
   int n = px->ReturnInt();  // calls X::ReturnInt through px
}

See Also

Managed Extensions for C++ Keywords | C++ Keywords