Garbage Collected Classes

Classes under C++ are usually allocated on the stack or the heap as required. Classes allocated with the new keyword must also be deleted in an orderly fashion to prevent memory leaks. Garbage Collected classes are allocated on the GC heap, are subject to lifetime management and movement by the GC, and will be deleted from the system only after the final reference to them has been released.

The declaration for a Garbage Collected class under managed C++ is as follows:

__gc class SomeClass
{
};

Under .NET, all classes that have no explicit base class are implicitly derived from System::Object. The managed C++ classes declared with __gc are also added to in this manner by the compiler. This base class has methods that you can override to improve interaction between your GC class and the system. See the System::Object methods in the .NET SDK documentation for more details.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.50.222