template<class T = RObject>
class CXXR::GCStackRoot< 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 GCStackRoot object exists, the GCNode that it points to will not be garbage collected.
GCStackRoot objects are intended to be allocated on the processor stack: specifically, the class implementation requires that GCStackRoot objects are destroyed in the reverse order of creation, and the destructor checks this.
- 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 GCStackRoot using the type GCStackRoot<const String>. |
- Caller protects:
- Suppose some code calls a function (or class method) that takes a pointer or reference to a class derived from GCNode as an argument, and/or returns a pointer to a class derived from GCNode as its return value. In CXXR, the preferred coding approach is that the calling code should take responsibility for protecting the arguments from the garbage collector before calling the function, and likewise take responsibility for protecting the returned value. This is because the calling code is in a better position to decide whether any additional steps are necessary to achieve this, and what they should be. (The calling code may also need to protect other objects: objects that are neither arguments to or values returned from the called function, but which would otherwise be vulnerable if the called function gave rise to a garbage collection.)
This class encapsulates a pointer to an object of a type derived from GCNode. For as long as the GCStackRoot object exists, the GCNode that it points to will not be garbage collected.
GCStackRoot objects are intended to be allocated on the processor stack: specifically, the class implementation requires that GCStackRoot objects are destroyed in the reverse order of creation, and the destructor checks this.
- 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 GCStackRoot using the type GCStackRoot<const String>. |
- Caller protects:
- Suppose some code calls a function (or class method) that takes a pointer or reference to a class derived from GCNode as an argument, and/or returns a pointer to a class derived from GCNode as its return value. In CXXR, the preferred coding approach is that the calling code should take responsibility for protecting the arguments from the garbage collector before calling the function, and likewise take responsibility for protecting the returned value. This is because the calling code is in a better position to decide whether any additional steps are necessary to achieve this, and what they should be. (The calling code may also need to protect other objects: objects that are neither arguments to or values returned from the called function, but which would otherwise be vulnerable if the called function gave rise to a garbage collection.)