template<class T = RObject>
class CXXR::GCRoot< T >
Smart pointer to protect a GCNode from garbage collection.
This class encapsulates a pointer to an object of a type derived from GCNode. For as long as the GCRoot object exists, the GCNode that it points to will not be garbage collected.
This class performs a similar function to GCStackRoot, but is intended for variables that are not allocated on the stack. Unlike GCStackRoot objects, there is no requirement that GCRoot objects be destroyed in the reverse order of their creation; the price of this is that there is a slightly greater time overhead to construction and destruction.
It is not recommended to declare a GCRoot (or indeed any object requiring non-trivial construction) at file or namespace scope in circumstances where the order of initialisation of data in different source files may be an issue. See the way in which Environment::s_base
is declared and initialised in Environment.cpp for a preferable approach.
- Template Parameters:
-
T | GCNode or a type publicly derived from GCNode. This may be qualified by const, so for example a const String* may be encapsulated in a GCRoot using the type GCRoot<const String>. |